Weier
Weier

Reputation: 1429

Automatically fill command line input of variable size

I have a Python script which asks for some arguments when running (using raw_input). I'd like to be able to run this script and feed it with some inputs (basically, I need to alternate between 2 values as long as it needs input).

I know how to feed it with a single value using the yes program but I don't know how to obtain a sequence like a b a b a b

What's the simplest way ?

Upvotes: 2

Views: 718

Answers (1)

John Kugelman
John Kugelman

Reputation: 362137

yes $'a\nb' | script.py

Uses bash's $'...' syntax for string literals which contain escape sequences. Alternatively:

while true; do echo a; echo b; done | script.py

Upvotes: 6

Related Questions