Converting a Shell Script to run under Python

Magnus L. Hetland mlh at vier.idi.ntnu.no
Mon Dec 6 19:14:30 EST 1999


"Austin Wilson" <wilson.austin.aj at bhp.com.au> writes:

> Hi
> 
> I was hoping someone may be able to help me convert the following Shell
> Script to perform the same functions under python. Basically it just reads a
> filename which is stored in file1 and then renames file2 to that name.

I suspect you'll get several responses in parallel here, but that's
just the spirit of c.l.p :)

> 
> #!/bin/sh
> read name < file1
> mv file2 $name
> rm file1

#!/usr/bin/env python
import os
name = open("file1").read()
os.rename("file2",name)
os.remove("file1")

(Remember not to put a newline character after the filename in
file1... :)

> 
> Thanks
> Austin
> 

--

  Magnus          Echelon jamming noise:
  Lie             FBI CIA NSA Handgun Assault Bomb Drug Terrorism
  Hetland         Special Forces Delta Force AK47 Hillary Clinton 




More information about the Python-list mailing list