#!/usr/bin/env python2

import sys
import os

def foreach_cmd(fp, cmd):
    if not '%s' in cmd:
        cmd += ' %s'

    while True:
        line = fp.readline().strip()
        if not line:
            break

        actual_cmd = cmd % line
        print 'foreach:', actual_cmd
        os.system(actual_cmd)

if __name__=='__main__':
    assert len(sys.argv) > 1, "Expected command, got nothing"
    cmd = ' '.join(sys.argv[1:])
    foreach_cmd(sys.stdin, cmd)

