ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Recently I asked for some ideas about porting a shell script to a cross platform scripting language.
I have no experience with Python or Perl, although learning both is on my to-do list.
I'm looking for a chart of some sort or mini how-to that explains which shell built-in and standard command line tools are available directly within the Python and Perl languages.
Specifically I am interested in these commands:
Shell built-in commands:
exit, for/done, if/then/fi, cd
I am aware of and have used the GNUWin32 ports of many standard command line tools, but the idea here is to reduce as much external command dependency as possible.
I think you're missing the point, you'll need to do things differently because it's not a shell script. Most languages have loop statements (for, if/else, while) but you won't have
In both languages you find the mentioned flow controls like if, else, while and such. Both allow to execute system commands and use the results.
in Perl you can say
system("echo 'aha'");
whereas in Python you need the subprocess module to do the same. (I havn't used Python very often so I can't tell in detail)
It looks like you have a fundamentally wrong idea of what a "real" programming language is like. It's not at all like shell scripting, and there are no "equivalents" for stuff like coreutils commands and shell builtins.
You might have to specify exactly what your script is currently doing and how it's using the features of those coreutils. As I think has been expressed, languages like perl and python provide many robust ways to control the flow of a program written in them, but you typically use the features found in their libraries rather than call shell utilities and therefore you need to know the basics of the language to performs the basics like echo or mv.
All of which depends on an understanding of the basics, like flow control.
Lastly, are you tied to perl or python? Because most IT departments would be happier supporting something like a Java app than getting python and tk packaged if you must create a nice GUI and remain crossplatform. The Java Runtime Environment is typically on most Windows machines for regular office builds. The Java documentation's very similarly structured. Java, or rather Oracle, dependency is becoming a concern, but for this small app, you might find it much quicker and easier to create and deploy a Java Swing GUI than something in other languages. But I haven't touched python in quite a while and just remember struggling a bit with tk and wxwindows/wxwidgets for GUIs. Also I have no real experience of perl, but afaik it's made for text manipulation, it's RE syntax is inherited in python and Java iirc.
Based on some of the replies, I did not explain myself well.
As I mentioned in my last sentence, the idea here is to reduce external command dependencies.
Shell scripts are wonderful in native 'nix environments but are not portable to other operating systems.
If I port a shell script to another language and that port must run on Windows, then I no longer want to depend upon common Linux tools and commands because I can't expect those tools to exist natively in Windows. Yes, there is Cygwin and GNUWin32 tools, but that requires installing that software, which creates external dependencies.
Therefore I am looking for how to perform the same tasks I perform in my shell script without the external dependencies.
Quote:
Most languages have loop statements (for, if/else, while)...
Yeah, I know that. I realized a few hours after posting that I should not have even mentioned those requirements.
Quote:
It's not at all like shell scripting, and there are no "equivalents" for stuff like coreutils commands and shell builtins.
That is part of what I did not explain properly. I am presuming I need to find libraries, functions, and procedures that perform the same results as the external commands used in a shell script. As I am unfamiliar with languages such as Perl, Python, or Java, I don't know how easily those same tasks can be rewritten.
Some preliminary reading indicates that Perl has some built in methods to simulate or perform the equivalent of external commands such as grep and sed. I was hoping I could find a more exhaustive list of these "equivalents."
Perl has many commands adapted from the shell/s and other tools like grep, sed, awk and many others. But Perl often does things on it's own way. Perl-regex for example has become more or less the de facto standard for regular expressions at all (this is not directly related to your question about shell commands).
I've written some Perl-scripts which I use on Windows-servers and these run on my Slackware-machine as well.
to your list from your first post:
Quote:
Originally Posted by Woodsman
Shell built-in commands:
exit, for/done, if/then/fi, cd
For "ls" you can chose between the Perl-commands opendir/readdir and the so called "backticks". Other than system the backticks make the ouput of a command available in the Perl-script, an example
Code:
#!/usr/bin/perl -w
my @filesinthisdirctory = `ls`;
will create an array @filesinthisdirectory with all the filenames.
When it comes to compatibility with Windows you'll have to make sure that different systemcommands are handled correct and that in pathes we us "/" in Linux but "\" in Windows. But you can let Perl find out which OS it is and put the various commands in an if-statement.
Almost all common languages come with functions for cross-platform file system manipulation. And they also usually automatically convert "/" to the OS's native path separator, so you don't even need to worry about that.
If you're going to do that, you might as well use a shell script. At least you won't need Perl as a dependency.
well, I just wanted to give an example
Quote:
Almost all common languages come with functions for cross-platform file system manipulation. And they also usually automatically convert "/" to the OS's native path separator, so you don't even need to worry about that.
That's interesting, I wasn't aware of that, thanks for the information.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.