Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Repeat.

Name: Anonymous 2013-09-29 17:24

$ cat repeat.py

import sys
import os
c = sys.argv[1]
i = int(sys.argv[2])

com = open('com.sh', 'w+')
com.write(c)
com.close()
os.system("chmod +x com.sh")

n = 0
while n <= i:
     n = n + 1
     os.system("./com.sh")


$cat repeat

#!/bin/bash
python repeat.py "$1" "$2"

if [ $? != 0 ] ; then
echo "
Usage: repeat ['command'] [# of times to repeat]
EG. repeat 'ls -a' 5
If the command contains spaces, it must be contained in quotes.
"
fi


Rate my code.

Name: Anonymous 2013-09-29 18:28

★☆☆☆☆

Name: Anonymous 2013-09-29 19:59

EXPERT quality

Name: Anonymous 2013-09-29 22:02

>>2
>>3
But wait. I found out how to get it to write to a directory in ~/

It is cleaner and better.

How would you guys go about making a program that takes two arguments, the first a shell command to execute, and the second being the number of times to repeat it?


import sys
import os
c = sys.argv[1]
i = int(sys.argv[2])
f = os.path.abspath(".com.sh")

com = open(f, 'w+')
com.write(c)
com.close()
os.system("chmod +x %r" % f)

n = 0
while n <= i:
     n = n + 1
     os.system("%r" % f)

Name: Anonymous 2013-10-02 21:02

You're using the wrong tool for the job.
Not sure if that's the joke.

#!/usr/bin/env zsh
n=0
while [[ n -lt $2 ]] {
    n=$(( $n + 1 ))
    eval $1
}


Or bash version
#!/usr/bin/env bash
n=0
while [[ n -lt $2 ]]; do
    n=$(( $n + 1 ))
    eval $1
done

Name: Anonymous 2013-10-02 21:10

By the way, look into the watch command. Probably comes with your os. man is your friend

Name: Anonymous 2013-10-02 22:16

>>6
man is a sexist command. I prefer to run the gender-agnostic GNU info utility instead.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List