|
|
|
|
|
by belorn
3297 days ago
|
|
If you want to maximize readability and simplicity then writing `yes` in C is a bad choice. It is much easier, cleaner and shorter to write it in python or just use the shell which would normally be using the `yes` in the first place. Since `yes` is used in shells and builtins can be considered very reliable, here is a implementation as a shell function: yes(){ while :; do echo "${1:-y}"; done; }
Python: import sys
while True:
if len(sys.argv) > 1:
print(sys.argv[1])
else:
print("y")
And if you don't need the features of `yes` and only need a loop that prints 'y', then there really is hard to beat the simplicity of: while:; do echo "y"; done
|
|
https://github.com/openbsd/src/blob/master/usr.bin/yes/yes.c
It's essentially line for line identical to your python code...