Q:

How to repeat a word or line

How can repeat a word or line on a number of lines, like the command foo in
$ foo 3 word 
word
word
word

or 
$ foo 2 An example line
An example line
An example line

with the same effect like
$ seq 3 | sed s/./word/
word
word
word

or
$ yes word | head -3
word
word
word

I had expected that seq supports that, but it does not, as far as I see.

A:

You don't need any external utilities to do that, but just use your native shell's internals with printf() functionality. For e.g. in a bash shell, you could do
foo() {
    if [ "$1" -lt 2 ]; then
        printf '%s\n' 'insufficient arguments provided' >&2
    fi

    local iter
    for (( iter = 1; iter <= $1; iter++ )); do
        printf '%s\n' "$2"
    done
}

Make sure to quote the word to be printed under quotes, so that the words are not split. E.g.
foo 3 bar
foo 3 'howdy world'

If you are looking for an external utility for the same, perl or awk can just do it as needed
printf '%s\n' 'howdy world' | perl -ne 'print $_ x 3' 

or 
printf '%s\n' 'howdy world' | awk '{ for (i = 1; i <= 3; i++) print $0 }'

Also BSD systems have a binary jot which can just repeat strings provided to it. Or in Ubuntu systems under athena-jot package.
jot -b 'howdy world' 3 

