PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > linux.debian.user > bash vs. python scripts - which one is better?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
linux.debian.user debian-user@lists.debian.org.

bash vs. python scripts - which one is better?

Réponse
 
LinkBack Outils de la discussion
Vieux 07/08/2007, 20h50   #1
Manon Metten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut bash vs. python scripts - which one is better?

Hi,

I'm about to learn bash or python scripting.

- Which one is easiest to learn?
- Which one is more powerful?
- Can I execute /bin commands from within a python script
(something like mkdir or ls)?

Or should I learn bash scripting anyway?
Please, let me know your experiences.

Thanks in advance, Manon.

  Réponse avec citation
Vieux 07/08/2007, 21h00   #2
Jose Luis Rivas Contreras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Manon Metten wrote:
> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?
> - Which one is more powerful?
> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?
>
> Or should I learn bash scripting anyway?


You should learn bash anyway .

I believe is easier that python, at least for system scripts, but if you
want to make something bigger, like an application then go for python.

Regards,
Jose Luis.
--

ghostbar on debian linux 'sid' 2.6.22 x86_64-SMP - #382503
Weblog: http://ghostbar.ath.cx/ - http://linuxtachira.org
http://debian.org.ve - irc.debian.org #debian-ve #debian-devel-es
San Cristóbal, Venezuela. http://chaslug.org.ve
Fingerprint = 3E7D 4267 AFD5 2407 2A37 20AC 38A0 AD5B CACA B118


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuMAJOKCtW8rKsRgRAlMsAJ98YhS+v+zRRO7ZBmHHez 8VRrPb3QCfdcPb
rtJn+s75UZ7xTjpnGnnlgBw=
=GY1S
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 07/08/2007, 21h00   #3
Jose Luis Rivas Contreras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Manon Metten wrote:
> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?
> - Which one is more powerful?
> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?
>
> Or should I learn bash scripting anyway?


You should learn bash anyway .

I believe is easier that python, at least for system scripts, but if you
want to make something bigger, like an application then go for python.

Regards,
Jose Luis.
--

ghostbar on debian linux 'sid' 2.6.22 x86_64-SMP - #382503
Weblog: http://ghostbar.ath.cx/ - http://linuxtachira.org
http://debian.org.ve - irc.debian.org #debian-ve #debian-devel-es
San Cristóbal, Venezuela. http://chaslug.org.ve
Fingerprint = 3E7D 4267 AFD5 2407 2A37 20AC 38A0 AD5B CACA B118


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuMAJOKCtW8rKsRgRAlMsAJ98YhS+v+zRRO7ZBmHHez 8VRrPb3QCfdcPb
rtJn+s75UZ7xTjpnGnnlgBw=
=GY1S
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 07/08/2007, 21h40   #4
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 11:42 AM, Manon Metten wrote:

> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?


That's debatable, I think. Bash's syntax is more idiosyncratic, but
there's less of it.

> - Which one is more powerful?


Python.

> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?


I'm sure you can, although I don't know how. (I'm not a Python
programmer.)

>
> Or should I learn bash scripting anyway?


If you plan to do much system administration, learning bash scripting
is worthwhile. There are three reasons I can think of right off the
bat:
- Every Unix-like system you encounter will have some version of the
Bourne shell. Not every system will have Python.
- You will often need to modify or maintain other people's bash
scripts, since that's how most startup scripts and the like are written.
- Simple bash scripts can be done right from the shell prompt, which
is sometimes handy.
Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE
$FILE.mp3 ; done' to encode a bunch of WAV files to MP3, to give a
crude example.




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 07/08/2007, 21h40   #5
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 11:42 AM, Manon Metten wrote:

> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?


That's debatable, I think. Bash's syntax is more idiosyncratic, but
there's less of it.

> - Which one is more powerful?


Python.

> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?


I'm sure you can, although I don't know how. (I'm not a Python
programmer.)

>
> Or should I learn bash scripting anyway?


If you plan to do much system administration, learning bash scripting
is worthwhile. There are three reasons I can think of right off the
bat:
- Every Unix-like system you encounter will have some version of the
Bourne shell. Not every system will have Python.
- You will often need to modify or maintain other people's bash
scripts, since that's how most startup scripts and the like are written.
- Simple bash scripts can be done right from the shell prompt, which
is sometimes handy.
Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE
$FILE.mp3 ; done' to encode a bunch of WAV files to MP3, to give a
crude example.




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 07/08/2007, 22h20   #6
Manon Metten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Hi David,

On 8/7/07, David Brodbeck <brodbd@u.washington.edu> wrote:

> I'm about to learn bash or python scripting.
> > - Which one is easiest to learn?

>
> That's debatable, I think. Bash's syntax is more idiosyncratic, but
> there's less of it.
>
> > - Which one is more powerful?

>
> Python.




> Or should I learn bash scripting anyway?
>
> If you plan to do much system administration, learning bash scripting
> is worthwhile. There are three reasons I can think of right off the
> bat:
> - Every Unix-like system you encounter will have some version of the
> Bourne shell. Not every system will have Python.
> - You will often need to modify or maintain other people's bash
> scripts, since that's how most startup scripts and the like are written.
> - Simple bash scripts can be done right from the shell prompt, which
> is sometimes handy.




I wish I'd discovers Linux some ten years ago. I have literally hundreds of
AmigaDOS and ARexx scripts - some of them very powerful - that don't
even come close to converting to bash (or maybe python). Now I feel I've
to re-invent the wheel.

Thanks for your input, Manon.

  Réponse avec citation
Vieux 07/08/2007, 22h20   #7
Manon Metten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Hi David,

On 8/7/07, David Brodbeck <brodbd@u.washington.edu> wrote:

> I'm about to learn bash or python scripting.
> > - Which one is easiest to learn?

>
> That's debatable, I think. Bash's syntax is more idiosyncratic, but
> there's less of it.
>
> > - Which one is more powerful?

>
> Python.




> Or should I learn bash scripting anyway?
>
> If you plan to do much system administration, learning bash scripting
> is worthwhile. There are three reasons I can think of right off the
> bat:
> - Every Unix-like system you encounter will have some version of the
> Bourne shell. Not every system will have Python.
> - You will often need to modify or maintain other people's bash
> scripts, since that's how most startup scripts and the like are written.
> - Simple bash scripts can be done right from the shell prompt, which
> is sometimes handy.




I wish I'd discovers Linux some ten years ago. I have literally hundreds of
AmigaDOS and ARexx scripts - some of them very powerful - that don't
even come close to converting to bash (or maybe python). Now I feel I've
to re-invent the wheel.

Thanks for your input, Manon.

  Réponse avec citation
Vieux 07/08/2007, 22h30   #8
Michael Marsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> I wish I'd discovers Linux some ten years ago. I have literally hundreds of
> AmigaDOS and ARexx scripts - some of them very powerful - that don't
> even come close to converting to bash (or maybe python). Now I feel I've
> to re-invent the wheel.


As a stop-gap, you might want to install regina-rexx . That'll at
least give you time to convert your scripts to something else. I've
never used REXX, but perusing the syntax on Wikipedia, it looks like
you should be able to convert a lot of it to bash "easily" once you've
familiarized yourself with the syntax.

And since you asked, I like python, but a working knowledge of bash is
indispensible.

--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com
http://36pints.blogspot.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 07/08/2007, 22h30   #9
Michael Marsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> I wish I'd discovers Linux some ten years ago. I have literally hundreds of
> AmigaDOS and ARexx scripts - some of them very powerful - that don't
> even come close to converting to bash (or maybe python). Now I feel I've
> to re-invent the wheel.


As a stop-gap, you might want to install regina-rexx . That'll at
least give you time to convert your scripts to something else. I've
never used REXX, but perusing the syntax on Wikipedia, it looks like
you should be able to convert a lot of it to bash "easily" once you've
familiarized yourself with the syntax.

And since you asked, I like python, but a working knowledge of bash is
indispensible.

--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com
http://36pints.blogspot.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 07/08/2007, 23h40   #10
Manon Metten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Hi Michael,

On 8/7/07, Michael Marsh <michael.a.marsh@gmail.com> wrote:

As a stop-gap, you might want to install regina-rexx . That'll at
> least give you time to convert your scripts to something else.



Gee, this is great. It looks very familiar. I don't think it won't take
long before I can use it. Thank you very much.


I've never used REXX, but perusing the syntax on Wikipedia, it looks
> like you should be able to convert a lot of it to bash "easily" once
> you've
> familiarized yourself with the syntax.
>
> And since you asked, I like python, but a working knowledge of bash is
> indispensible.



Thanks for your input, Manon.

  Réponse avec citation
Vieux 07/08/2007, 23h40   #11
Manon Metten
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

Hi Michael,

On 8/7/07, Michael Marsh <michael.a.marsh@gmail.com> wrote:

As a stop-gap, you might want to install regina-rexx . That'll at
> least give you time to convert your scripts to something else.



Gee, this is great. It looks very familiar. I don't think it won't take
long before I can use it. Thank you very much.


I've never used REXX, but perusing the syntax on Wikipedia, it looks
> like you should be able to convert a lot of it to bash "easily" once
> you've
> familiarized yourself with the syntax.
>
> And since you asked, I like python, but a working knowledge of bash is
> indispensible.



Thanks for your input, Manon.

  Réponse avec citation
Vieux 08/08/2007, 00h00   #12
Vincent Lefevre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 2007-08-07 12:39:37 -0700, David Brodbeck wrote:
> On Aug 7, 2007, at 11:42 AM, Manon Metten wrote:
>> I'm about to learn bash or python scripting.


Why not zsh (more powerful than bash) or perl?

>> Or should I learn bash scripting anyway?

>
> If you plan to do much system administration, learning bash scripting is
> worthwhile. There are three reasons I can think of right off the bat:
> - Every Unix-like system you encounter will have some version of the Bourne
> shell. Not every system will have Python.


Not every system has bash. If this is for compatibility, you can learn
POSIX sh, but e.g. Solaris /bin/sh is not a POSIX sh. For this reason
and because POSIX sh is limited (you can't execute a command and have
a timeout on it), I now write all my portable scripts in Perl since it
is on every system I've met.

> - You will often need to modify or maintain other people's bash scripts,
> since that's how most startup scripts and the like are written.
> - Simple bash scripts can be done right from the shell prompt, which is
> sometimes handy.
> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ;
> done' to encode a bunch of WAV files to MP3, to give a crude example.


This one is bad. Really.

for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done

This is another reason why sh sucks. It's too easy to write broken
things.

--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 00h00   #13
Vincent Lefevre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 2007-08-07 12:39:37 -0700, David Brodbeck wrote:
> On Aug 7, 2007, at 11:42 AM, Manon Metten wrote:
>> I'm about to learn bash or python scripting.


Why not zsh (more powerful than bash) or perl?

>> Or should I learn bash scripting anyway?

>
> If you plan to do much system administration, learning bash scripting is
> worthwhile. There are three reasons I can think of right off the bat:
> - Every Unix-like system you encounter will have some version of the Bourne
> shell. Not every system will have Python.


Not every system has bash. If this is for compatibility, you can learn
POSIX sh, but e.g. Solaris /bin/sh is not a POSIX sh. For this reason
and because POSIX sh is limited (you can't execute a command and have
a timeout on it), I now write all my portable scripts in Perl since it
is on every system I've met.

> - You will often need to modify or maintain other people's bash scripts,
> since that's how most startup scripts and the like are written.
> - Simple bash scripts can be done right from the shell prompt, which is
> sometimes handy.
> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ;
> done' to encode a bunch of WAV files to MP3, to give a crude example.


This one is bad. Really.

for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done

This is another reason why sh sucks. It's too easy to write broken
things.

--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 00h20   #14
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote:
>> - Every Unix-like system you encounter will have some version of
>> the Bourne
>> shell. Not every system will have Python.

>
> Not every system has bash.


Well, yeah. That's why I said "Bourne shell" and not "bash."

> I now write all my portable scripts in Perl since it
> is on every system I've met.


It's not any more guaranteed than bash, though. For example, FreeBSD
no longer includes Perl with the base system; you have to install it
as a port.

>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE
>> $FILE.mp3 ;
>> done' to encode a bunch of WAV files to MP3, to give a crude example.

>
> This one is bad. Really.
>
> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done
>
> This is another reason why sh sucks. It's too easy to write broken
> things.


Good catch, and I should have known better than to throw something
like that out there instead of using a real, debugged example. Every
language has its issues; with bash it's argument escaping.

Personally I think filenames with spaces in them are an abomination
that should have never been permitted, but I lost that argument ages
ago.



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 00h20   #15
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote:
>> - Every Unix-like system you encounter will have some version of
>> the Bourne
>> shell. Not every system will have Python.

>
> Not every system has bash.


Well, yeah. That's why I said "Bourne shell" and not "bash."

> I now write all my portable scripts in Perl since it
> is on every system I've met.


It's not any more guaranteed than bash, though. For example, FreeBSD
no longer includes Perl with the base system; you have to install it
as a port.

>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE
>> $FILE.mp3 ;
>> done' to encode a bunch of WAV files to MP3, to give a crude example.

>
> This one is bad. Really.
>
> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done
>
> This is another reason why sh sucks. It's too easy to write broken
> things.


Good catch, and I should have known better than to throw something
like that out there instead of using a real, debugged example. Every
language has its issues; with bash it's argument escaping.

Personally I think filenames with spaces in them are an abomination
that should have never been permitted, but I lost that argument ages
ago.



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 00h30   #16
Nelson Castillo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?


Python I guess.

> - Which one is more powerful?


Python.

> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?


Yes.

http://www.oreilly.com/catalog/lpyth...h09.html#13504

> Or should I learn bash scripting anyway?


Yes I learnt Perl because I didn't want to learn Bash. But once
in a while I'd like to be fluent in Bash so I can write nice one-liners.
Nowadays I replaced Perl with Python, but I still use Perl from time
to time (to write one-liners mostly).

> Please, let me know your experiences.


Learn how to use 'find'. It's very useful.
Also regular expressions.

You might want to check the OS module, and look for some
examples.

http://docs.python.org/lib/module-os.html

Regards,
N.-

--
http://arhuaco.org
http://emQbit.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 00h30   #17
Nelson Castillo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> Hi,
>
> I'm about to learn bash or python scripting.
>
> - Which one is easiest to learn?


Python I guess.

> - Which one is more powerful?


Python.

> - Can I execute /bin commands from within a python script
> (something like mkdir or ls)?


Yes.

http://www.oreilly.com/catalog/lpyth...h09.html#13504

> Or should I learn bash scripting anyway?


Yes I learnt Perl because I didn't want to learn Bash. But once
in a while I'd like to be fluent in Bash so I can write nice one-liners.
Nowadays I replaced Perl with Python, but I still use Perl from time
to time (to write one-liners mostly).

> Please, let me know your experiences.


Learn how to use 'find'. It's very useful.
Also regular expressions.

You might want to check the OS module, and look for some
examples.

http://docs.python.org/lib/module-os.html

Regards,
N.-

--
http://arhuaco.org
http://emQbit.com


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 01h00   #18
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 05:28:54PM -0500, Nelson Castillo wrote:
>
> Learn how to use 'find'. It's very useful.
> Also regular expressions.
>


Recently I've begun picking up (mostly by osmosis and from reading
Florian's posts) a lot more awk, find, and regex. Those three combined
with xargs or find -exec can get a pile of work done really quickly.

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuPkVaIeIEqwil4YRAs5zAKCLD4d5jfFKwccmJ/alzswxRt29HgCgo3cn
gdSzhT37Wnr5RfWEgjH7KBo=
=Teez
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 08/08/2007, 01h00   #19
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 05:28:54PM -0500, Nelson Castillo wrote:
>
> Learn how to use 'find'. It's very useful.
> Also regular expressions.
>


Recently I've begun picking up (mostly by osmosis and from reading
Florian's posts) a lot more awk, find, and regex. Those three combined
with xargs or find -exec can get a pile of work done really quickly.

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuPkVaIeIEqwil4YRAs5zAKCLD4d5jfFKwccmJ/alzswxRt29HgCgo3cn
gdSzhT37Wnr5RfWEgjH7KBo=
=Teez
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 08/08/2007, 01h10   #20
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 03:14:42PM -0700, David Brodbeck wrote:
>
> On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote:
>>> - Every Unix-like system you encounter will have some version of the
>>> Bourne
>>> shell. Not every system will have Python.

>>
>> Not every system has bash.

>
> Well, yeah. That's why I said "Bourne shell" and not "bash."
>
>> I now write all my portable scripts in Perl since it
>> is on every system I've met.

>
> It's not any more guaranteed than bash, though. For example, FreeBSD no
> longer includes Perl with the base system; you have to install it as a
> port.
>
>>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3
>>> ;
>>> done' to encode a bunch of WAV files to MP3, to give a crude example.

>>
>> This one is bad. Really.
>>
>> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done
>>
>> This is another reason why sh sucks. It's too easy to write broken
>> things.



So what's the right way to do this? I hacked one together the other
day:

IFS=$'\t\n'; for i in `find . -iname \*m4a`; do faad... blah blah blah

and I knew it was a hack because setting $IFS just seems
bad... possible unintended consquences, but it worked.

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuPopaIeIEqwil4YRAnKRAJ9PqqMz7rBfHOYy6Pdspp lXkqgq1gCgylhH
BeTXAS8WhHYK2HuvRbflHyo=
=b8cy
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 08/08/2007, 01h10   #21
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 03:14:42PM -0700, David Brodbeck wrote:
>
> On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote:
>>> - Every Unix-like system you encounter will have some version of the
>>> Bourne
>>> shell. Not every system will have Python.

>>
>> Not every system has bash.

>
> Well, yeah. That's why I said "Bourne shell" and not "bash."
>
>> I now write all my portable scripts in Perl since it
>> is on every system I've met.

>
> It's not any more guaranteed than bash, though. For example, FreeBSD no
> longer includes Perl with the base system; you have to install it as a
> port.
>
>>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3
>>> ;
>>> done' to encode a bunch of WAV files to MP3, to give a crude example.

>>
>> This one is bad. Really.
>>
>> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done
>>
>> This is another reason why sh sucks. It's too easy to write broken
>> things.



So what's the right way to do this? I hacked one together the other
day:

IFS=$'\t\n'; for i in `find . -iname \*m4a`; do faad... blah blah blah

and I knew it was a hack because setting $IFS just seems
bad... possible unintended consquences, but it worked.

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuPopaIeIEqwil4YRAnKRAJ9PqqMz7rBfHOYy6Pdspp lXkqgq1gCgylhH
BeTXAS8WhHYK2HuvRbflHyo=
=b8cy
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 08/08/2007, 01h30   #22
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote:
> oh. I see. That is the right one. but, doesn't really work if you need
> to recurse into stuff does it, which was my problem with that find in
> the previous post.


To do this with find, I'd try something like this:

find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \;

It's possible spaces will bite you here, too ... If you actually
attempt this on filenames with spaces, test it first and see if you
need to add another level of quoting. Note that you have to escape
the curly brackets and the semicolon so find sees them, instead of
bash trying to interpret them. Find's syntax for the "exec" action
is kind of awkward-looking, but this can be an extremely useful
tool. For example, I once had to decompress a bunch of gzipped files
in a directory tree, so I did something like this:

find . -name "*.gz" -exec gunzip \{\} \;

Note that find -exec can also do a lot of damage in a hurry. If
you're doing anything remotely destructive, you might want to
substitute "echo \{\}" for your command the first time you run it,
just to make sure find is only finding the stuff you want it to!
Also, before you start thinking of doing anything resembling "-exec
rm" note that find has a built-in ability to delete files.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 01h30   #23
David Brodbeck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?


On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote:
> oh. I see. That is the right one. but, doesn't really work if you need
> to recurse into stuff does it, which was my problem with that find in
> the previous post.


To do this with find, I'd try something like this:

find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \;

It's possible spaces will bite you here, too ... If you actually
attempt this on filenames with spaces, test it first and see if you
need to add another level of quoting. Note that you have to escape
the curly brackets and the semicolon so find sees them, instead of
bash trying to interpret them. Find's syntax for the "exec" action
is kind of awkward-looking, but this can be an extremely useful
tool. For example, I once had to decompress a bunch of gzipped files
in a directory tree, so I did something like this:

find . -name "*.gz" -exec gunzip \{\} \;

Note that find -exec can also do a lot of damage in a hurry. If
you're doing anything remotely destructive, you might want to
substitute "echo \{\}" for your command the first time you run it,
just to make sure find is only finding the stuff you want it to!
Also, before you start thinking of doing anything resembling "-exec
rm" note that find has a built-in ability to delete files.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 08/08/2007, 01h50   #24
Andrew Sackville-West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 04:23:28PM -0700, David Brodbeck wrote:
>
> On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote:
>> oh. I see. That is the right one. but, doesn't really work if you need
>> to recurse into stuff does it, which was my problem with that find in
>> the previous post.

>
> To do this with find, I'd try something like this:
>
> find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \;


I do this one frequently to tar up small video files from a
surveillance system

find ./cam{1,2} -daystart -mtime +3 -exec tar -xzf '{}' + &

and its all over but for the processing.
>
> It's possible spaces will bite you here, too ... If you actually attempt
> this on filenames with spaces, test it first and see if you need to add
> another level of quoting.


its inevitable that these sorts of tasks have to be done on exactly
the kinds of files systems that have space: music folders or some
such...

Note that you have to escape the curly brackets
> and the semicolon so find sees them, instead of bash trying to interpret
> them. Find's syntax for the "exec" action is kind of awkward-looking, but
> this can be an extremely useful tool. For example, I once had to
> decompress a bunch of gzipped files in a directory tree, so I did something
> like this:
>
> find . -name "*.gz" -exec gunzip \{\} \;
>
> Note that find -exec can also do a lot of damage in a hurry. If you're
> doing anything remotely destructive, you might want to substitute "echo
> \{\}" for your command the first time you run it, just to make sure find is
> only finding the stuff you want it to! Also, before you start thinking of
> doing anything resembling "-exec rm" note that find has a built-in ability
> to delete files.


hmm... i'll look into that rm feature, but yes I routinely use -exec
echo '{}' first...

Regardless, its powerful and fun and once you've learned it, its
incredibly efficient. my wife gets frustrated watching over my
shoulder as I usually have to take a few cracks at it before I get it
right. She says something about how she could be done already using
the mouse and then I change from my sample tree to the real one and
process several hundred files in about 20 keystrokes... then I get to
be smug.

A

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGuQPHaIeIEqwil4YRAtXuAKDB34vYBk6y4NahOwEB05 TCVb9DvgCdHQGD
EGscaWF93yixUKnmgWwXI9Q=
=azf/
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 08/08/2007, 01h50   #