cross-platform shell scripts

C

Claudio

Hi,

I'm almost new to Perl and I only know the basics.
I would like to use it for creating cross-platform shell scripts
(Windows and Unix ).
I suppose Perl is appropriate for this task.
Should I look at any module in particular?

Thanks!

-Claudio
 
J

Jürgen Exner

Claudio said:
I would like to use it for creating cross-platform shell scripts
(Windows and Unix ).

Well, do you know for certain that your Windows users installed a shell
(e.g. tsch, bash, or whatever) on their boxes?
I suppose Perl is appropriate for this task.

Somewhere you lost me. Where would you use _Perl_ for writing _shell_
scripts?
It is like asking if Pascal is appropriate for writing COBOL programs.

jue
 
I

ioneabu

I think I see what you mean. There are a lot of tools that are
available on Unix systems by default that are either non-existent for
Windows or have to be installed by the user. Perl is said to replace
Sed and Awk and probably a lot of other Unix programs. That would make
Perl ideal for portable scripts that you might otherwise write with one
of these other programs.

I was wondering if there is any point in learning Sed, Awk or other
programming tools if you are already learning Perl. I started reading
the O'Reilly Sed/Awk book a little and I keep thinking with each
example, "I could just do this in Perl."

wana
 
R

Robert Sedlacek

Jürgen Exner said:
Somewhere you lost me. Where would you use _Perl_ for writing _shell_
scripts?

I think he meant 'Shell _started_ scripts/programs'. But I would suggest a
first look on cygwin, before reinventing wheels or start using lesser-good
reinvented wheels.

g,
Robert
 
C

Claudio

Said in another way, I would like to write Perl programs instead of
Unix shell scripts and Windows batch files.

Try to imagine tasks that you would perform using a shell script...
....ok, now try to imagine how you would do the same using Perl.

Of course I am not talking about language constructs, I'm talking about
modules that implement portable libraries to emulate the usual tasks
that you do in shell scripts.

Using your context, I didn't ask whether Pascal is good for writing
COBOL programs, I asked whether there are Pascal libraries that could
simplify my job of writing programs to deal with fixed-length
records...

-Claudio
 
R

Robert Sedlacek

Claudio said:
Of course I am not talking about language constructs, I'm talking about
modules that implement portable libraries to emulate the usual tasks that
you do in shell scripts.

Ah, i see. Maybe you want to watch out for Pure-Perl[0] modules on cpan.

g,
Robert

[0] If I understood them right.
 
C

Chris Mattern

Claudio said:
Hi,

I'm almost new to Perl and I only know the basics.
I would like to use it for creating cross-platform shell scripts
(Windows and Unix ).
I suppose Perl is appropriate for this task.

Perl is excellent for this task.
Should I look at any module in particular?
That depends entirely on what you want to do. Many things will
simply work on both Unix and Windows without any need to change
anything. Other things will run into differences between the
systems that Perl can't hide.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
B

botfood

most typical admin tasks are well handled by standard perl installs on
each platform... there are *some* differences that are pretty well laid
out by Oreilly "gecko" book learning perl on win32 systems. In the rare
case you need to do something non-transparent, you can check the OS and
make a different call from inside your "portable" script.

d
 
M

Mitja

Well, do you know for certain that your Windows users installed a shell
(e.g. tsch, bash, or whatever) on their boxes?

Windows user _do_ have a shell installed. It's called explorer.exe. The
shell is an integral part of every OS, that's why it's called the way it
is. It encloses the inner workings of the OS and provides an interface for
users.

From dictionary.com:
The command interpreter used to pass
commands to an operating system; so called because it is the
part of the operating system that interfaces with the outside
world.
Somewhere you lost me. Where would you use _Perl_ for writing _shell_
scripts?
Sure, perl programs that interact with the shell, be it bash, cmd or
anything else. He most probably wants to create file manipulation scripts
independent of the OS, using Perl as THE layer taking care of most
problems and OS differences.
 
J

Jürgen Exner

Mitja said:
Windows user _do_ have a shell installed. It's called explorer.exe.

You may want to check your references.
Explorer.exe is a web browser (with some added functionality). I certainly
wouldn't consider it a "shell".
Actually, which script language to you use to for a shell script, that runs
on explorer.exe?

Maybe you meant cmd.exe or command.com?
The shell is an integral part of every OS, that's why it's called the
way it is. It encloses the inner workings of the OS and provides an
interface for users.

From dictionary.com:
The command interpreter used to pass
commands to an operating system; so called because it is the
part of the operating system that interfaces with the outside
world.

How does explorer.exe interface between the inner workings of the OS and the
outside world?
Sure, perl programs that interact with the shell, be it bash, cmd or
anything else. He most probably wants to create file manipulation
scripts independent of the OS, using Perl as THE layer taking care of
most problems and OS differences.

Ok, that of course is a totally different question. And obvoiously Perl is
well suited for such a task because it is inherently portable.

jue
 
J

Jürgen Exner

Claudio said:
Said in another way, I would like to write Perl programs instead of
Unix shell scripts and Windows batch files.

Ah, ok, that makes much more sense.
Of course I am not talking about language constructs, I'm talking
about modules that implement portable libraries to emulate the usual
tasks that you do in shell scripts.

Usually not necessary because Perl programs are inherently portable unless
you deliberately make them non-portable.
Some things to watch out for:
- don't use external programs, i.e. don't use system(), backticks, qx//,
..... Chances are that external programs don't exist on other platforms.
Luckily most task which in shell require an external tool can be done
directly in native Perl without any problem
- use a forward slash as directory separator, not a backslash. While you can
use either one on WIndows Unix doesn't like the backslash.
- use the smallest common denominator for file names, i.e. Unix allows more
characters in file names than Windows. So use Windows restrictions.
- don't use absolute paths because the root in Unix and the root in Windows
are different.
Using your context, I didn't ask whether Pascal is good for writing

Who is "you"? I'm guessing you are replying to my answer, but please follow
standard customs and quote those text pieces which you are refering to.
COBOL programs, I asked whether there are Pascal libraries that could
simplify my job of writing programs to deal with fixed-length
records...

Well, to make the connection back to rewriting shell scripts in Perl: You
may consider Perl to be a much enhanced superset of shell scripting and
usually there is no need for any additional library to emulate shell script
behaviour. Even more, many of the tasks, which require forking of an
external program in shell, can be done more easily in native Perl.

jue
 
T

Tad McClellan

Jürgen Exner said:
How does explorer.exe interface between the inner workings of the OS and the
outside world?


It is FM. (the "M" is for magic)

And that's all you need to know, so don't ask again. :)
 
R

Robert Sedlacek

Jürgen Exner said:
How does explorer.exe interface between the inner workings of the OS and
the outside world?

Through security holes?

scnr,
Robert
 
M

Mitja

You may want to check your references.
Explorer.exe is a web browser (with some added functionality). I
certainly wouldn't consider it a "shell".
I beleive that would be iexplore.exe, not explorer.exe. In Win 2k/NT, you
can check the task manager.
Actually, which script language to you use to for a shell script, that
runs on explorer.exe?
Maybe you meant cmd.exe or command.com?
Hmmm.... I must admit I'm a bit at a loss here. cmd and command - yes, I'd
say they are shells alright. I still think, however, that explorer.exe
(_not_ MSIE) is a shell as well, and the more frequently used one at that.
Consider - the so called "shell extensions" in windows usually provide
extra functionality/option in the start menu / right-click menus / etc.
This further supports the idea of explorer.exe as a shell.

You did get me a bit confused with that question :)
I just did a search on google for "explorer.exe" windows shell, and the
results sum up my arguments pretty well.
How does explorer.exe interface between the inner workings of the OS and
the outside world?
With its GUI. But we were not talking about the same explorer here (see
above).
 
M

Michele Dondi

You may want to check your references.
Explorer.exe is a web browser (with some added functionality). I certainly

I think this could get more into phylosophy than computer science. But
I'd call explorer a shell: a GUI-based shell. Of course it's not a
command line shell.
wouldn't consider it a "shell".
Actually, which script language to you use to for a shell script, that runs
on explorer.exe?

I don't think a "shell" is charachterized by definition in terms of
"the possibility of using a script language for it". Or were you
referring to the subject of this thread?

However I'm sure there are hooks to allow one to interface his/her
program to it. A suitable such language is Perl with the appropriate
modules.
Maybe you meant cmd.exe or command.com?

These are indeed cmd line shells.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top