LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux scripting (https://www.linuxquestions.org/questions/linux-newbie-8/linux-scripting-863401/)

sfx81 02-17-2011 04:48 PM

Linux scripting
 
Hi All, I recently started learning linux. When people say shell scripting, does it always has to be bash/c/k shells ? Can't I just use perl/python ? PS will it still be quick as shall ?

Snark1994 02-17-2011 04:53 PM

You can :) you can use them just the same way, except instead of
Code:

#!/bin/bash
at the start of your script, you'd use
Code:

#!/usr/bin/python
(or perl!)

However, when people say "shell scripting" they normally are talking about bash scripts, in my experience. And I think the performance would be comparable, if not better :)

TB0ne 02-17-2011 05:25 PM

Quote:

Originally Posted by sfx81 (Post 4262092)
Hi All, I recently started learning linux. When people say shell scripting, does it always has to be bash/c/k shells ? Can't I just use perl/python ? PS will it still be quick as shall ?

I agree with Snark, but there's a bit of a distinction in my mind.

Perl and Python are interpreted languages (http://en.wikipedia.org/wiki/Interpreted_language), whereas bash and other 'shells' are more of a command environment. You can do SOME programming in bash, but if you want to go beyond basic functions, you're going to find yourself struggling. Perl and python (and there are others), are 'real' programming languages, capable of doing object-oriented processing, GUI windows, and serious math, amongst others.

Think about it like this..in Windows, you can write a batch file to do alot of different things. That's the equivalent of BASH scripting. More power needed? Then you're going to have to go to a different language, like perl, which gives you more programming power. Yes, you can 'compile' perl (check out the perl packager), to ship executables without shipping your source code. Those languages run a bit slower, since the code is 'compiled' at run time, versus being pre-compiled like a C program would be...but once they're both running, the difference isn't that bad.

chrism01 02-17-2011 07:42 PM

... and in actual fact for Perl, it (perl binary) reads your Perl prog an 'compiles it on the fly', then runs the 'compiled' version in memory.
Read this for the details http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html. The net effect is that it's not that much slower than an equiv C prog (85% ?).
Contrast with any of the shells eg ksh/bash which are true interpreted langs ie each cmd is re-parsed into machine lang each time it is called. Much slower than C or even Perl.

Snark1994 02-18-2011 07:41 AM

Quote:

Originally Posted by chrism01 (Post 4262210)
... and in actual fact for Perl, it (perl binary) reads your Perl prog an 'compiles it on the fly', then runs the 'compiled' version in memory.

I'm pretty sure this is also done in python... Not entirely certain though :)

yngwin 02-18-2011 10:03 AM

Shell scripting is specific to the shell, and is normally bash (altho other shells are sometimes also used). Perl, Python and similar interpreted programming languages are not normally used as shell (altho at least with Python this is possible). It is still scripting, but it works a bit different.


All times are GMT -5. The time now is 03:30 AM.