Sponsored Content
Top Forums Shell Programming and Scripting Conversion of Perl Script to Shell Script.. Post 302929463 by Corona688 on Monday 22nd of December 2014 12:30:50 AM
Old 12-22-2014
Quote:
Originally Posted by ongoto
@ Corona688

The devils' advocate here. Smilie
You're right. Calling 'uname -r' is not a call to the shell.
In perl, it is. It runs an entire complete shell, for convenience, to run a single command.

Quote:
/bin/uname is a binary that has nothing to do with the shell. I should say 'system calls' instead.
That's is not what "system call" means.

It is a fork(), an exec(), and probably several dup()'s, pipe()'s, reads(), and write()s on the perl side -- then all the same on the bash side. And then, finally, uname gets to do the system call to get the system's name and prints it into that pipe.

Creating a process is actually a fair amount of work, which is why it's generally done as little as possible. Doubling the amount of work necessary for it is not efficient, which is why perl makes a poor shell replacement.
Quote:
Some say that, because Perl uses system calls, you might as well use Bash. That presumes that Linux binaries are Bash builtins.
That's not what "system call" means.

You have completely missed my point, besides.
Quote:
If you call uname or ping, or any other binary from Bash; is that different than calling one from Perl?
Yes.

Yes, it is.

That is my point.

When you call an external command in perl, it just calls bash to do the real work for it, so that it nicely separates parameters and parses the way BASH has taught you to expect. Imagine if BASH had to call Perl to do anything, and you get an idea just how roundabout an arrangement this is.

You can avoid this by doing fork() and exec() instead of system(), but then you don't get all the nice things a shell does for you, like waiting for the process to finish and properly reaping it.
Quote:
You dont have to fork a shell to run Linux binaries.
You don't have to fork a shell, but you do have to fork. That's just how it works -- fork() to create a copy of yourself, then exec() to turn the copy into something else. In BASH, you fork once. In Perl you fork twice -- the first time, to create bash! The second time is bash fork()-ing then exec()-ing whatever.
Quote:
Most returns go to stdout or stderr. Why would you need a shell.
Exactly!

Whenever you do system() in perl, that uses a shell. For that matter, system() in lots of languages uses a shell -- including C and awk. That's just what system() means -- run this command in a native shell. In UNIX, that's a Bourne shell of some sort. In Windows, system() launches a Windows CMD interpreter.

Whenever you do ` ` in perl, that uses a shell too. Pretty sure Perl's popen-equivalent does also.

It's very inefficient if you're dealing with a lot of little commands. Twice the amount of work to use a process in Perl than BASH.

Why does it do this? Because BASH actually does a whole lot of things for you, to the point you haven't realized the problems it solves actually exist yet. Being able to say system("uname") instead of system("/usr/bin/uname"); works because BASH looks that up for you. To properly duplicate this and all the other little niceties the shell has taught you are "normal" would mean adding a lot more than you might expect.

Last edited by Corona688; 12-22-2014 at 02:25 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conversion of bash parsing script to perl?

I need help with a perl parsing script. I have some error logs on a windows machine that I need to parse from a text file, but I know nothing about perl. I usually run this bash script on my linux box and it does just what I need. How would I do the same thing with perl and port it to my windows... (2 Replies)
Discussion started by: cstovall
2 Replies

2. Shell Programming and Scripting

Help me with file conversion [Shell Script]

Hello Group, I request your help with a shell script for filter an ascii file (this is small piece of the file): 09/24/2009,00:00,1.0268,1.0268,1.0249,1.0250,518 09/24/2009,01:00,1.0251,1.0261,1.0249,1.0259,424 09/24/2009,02:00,1.0258,1.0272,1.0258,1.0269,372... (3 Replies)
Discussion started by: csierra
3 Replies

3. Shell Programming and Scripting

Encoding conversion in PERL script

I have oracle 9i database installed with UTF-8 Encoding. I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database For example : the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Discussion started by: vkca
6 Replies

4. AIX

Need timestamp conversion shell script !!

Can anyone provide me with a ksh or bash script which will accept a timestamp (format is YYYY-MM-DD-HH24.Mi.Ss) and time offset (in hours). The output will be (timestamp passed - time offset passed deducted from it) in the same YYYY-MM-DD-HH24.Mi.Ss format. Basically I am trying to convert the... (1 Reply)
Discussion started by: shibajighosh
1 Replies

5. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

6. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

7. Shell Programming and Scripting

Help required for Oracle database shutdown script conversion from shell to perl

Please tell me how to convert below program from shell script to perl. Same commands need to use in shutdown, just need program help for startup. export ORACLE_BASE=/home/oracle1 lsnrctl start lndb1 sqlplus '/ as sysdba' startup; (2 Replies)
Discussion started by: learnbash
2 Replies

8. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

9. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

10. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies
All times are GMT -4. The time now is 03:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy