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

Rewrite this in any language

Name: Anonymous 2013-09-20 16:28

#!/bin/bash
a="$1"
i=0
while [ $i < $2 ] ; do
    i=$(( i + 1 ))
    cp "$a" "${a%.jpg}"$i.jpg
done


Rewrite this in any language please. (Hint for those that don't know bash, $1, $2, $3 and so are arguments given from the command line, basically argv.)

I have all of it written in python except I can't get the damn shutil to accept the value of i as part of the filename, keeps complaining that it needs a string/buffer, and open(filename, 'wb').write(foo) doesn't work.

Name: Anonymous 2013-09-20 16:32

install gentoo

Name: Anonymous 2013-09-20 16:54

while [ $i < $2 ]
What the hell are you doing here? Perhaps you meant $i -lt $2?

Name: Anonymous 2013-09-20 17:09

>>3
Oh shit I'm sorry.

I accidentally copy/pasted that without changing it back.

while [ $i -le $2 ] ; do

Name: Anonymous 2013-09-20 17:48

try

cp "$a" "${a%.jpg}$i.jpg"

Name: Anonymous 2013-09-20 18:03

>>5
The script works perfectly fine.

I just wanted to see it wrote in another language out of fun/curiosity.

Name: Anonymous 2013-09-20 18:33

#!/usr/bin/perl
use File::Copy;
$a = shift;
$c = shift;
while ($i++ < $c) {
    ($b = $a) =~ s/(\.jpg)$/$i$1/;
    copy $a => $b;
}

Name: Anonymous 2013-09-20 20:33

#!/usr/bin/env zsh
a=$1
i=0
while [[ $i < $2 ]]; {
    i=$(( i + 1 ))
    cp $a ${a%.jpg}$i.jpg
}


More seriously:

I have all of it written in python except I can't get the damn shutil to accept the value of i as part of the filename, keeps complaining that it needs a string/buffer

filename = "%s%d.jpg" % (old_filename.replace(".jpg", ""), i)

Name: Anonymous 2013-09-20 21:16

install gentoo

Name: Anonymous 2013-09-20 21:23

>>8
% is deprecated, use the .format method instead

Name: Anonymous 2013-09-20 21:45

                        ██████████████████████                                                                           
      ██████████████████                      ████            ██████████████    ████    ██    ██  ██████    ████    ██    ██
    ██                      ██                    ████  ████████████████████  ██    ██  ██    ██  ██      ██    ██  ██  ██
    ██                  ████            ██            ████    ██████████████  ██        ████████  ████    ██        ████ 
      ██████████████████          ██████                ██    ██████████████  ██    ██  ██    ██  ██      ██    ██  ██  ██
                    ██        ████    ██                ██    ██████████████    ████    ██    ██  ██████    ████    ██    ██
                    ██████████        ██                ██    ██████████████                                             
                      ██          ████  ██              ██    ██████████████  ██████████  ██    ██  ██████  ██      ██   
                        ██████████      ██              ██    ██████████████      ██      ██    ██  ██      ████  ████   
                          ██        ████  ██            ██    ██████████████      ██      ████████  ████    ██  ██  ██   
                            ████████      ██            ██    ██████████████      ██      ██    ██  ██      ██      ██   
                            ██        ████              ██    ██████████████      ██      ██    ██  ██████  ██      ██   
                              ████████            ████████    ██████████████                                             
                                      ████████████      ████████████████████                                             
                                                              ██████████████

Name: Anonymous 2013-09-21 2:29

>>10
this is patently untrue, % works in py3

it is my opinion that .format() is overly complicated for uses like above. i believe the py devs were met with backlash at %'s formatting uses: the manual says .format() supplements %, not deprecates

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