system call - how-to.

E

elsiddik

well i wanted to just mess a little with perl and try if it can give
me the same result of a small shell script i wrote a little while ago
but it doesnt seems to work out with me . here is my shell script

#!/bin/bash
DIRECTORY="/usr/bin"
for file in $DIRECTORY/*
do whatis `basename $file`

done
exit 0

i tried to run a similiar perl code by typing on command line.

perl -e "system qw (whatis /usr/bin/*)"

but its not giving me the same whatislog - what am i doing wrong ?

cheers.


zaher el siddik
 
P

Paul Lalli

well i wanted to just mess a little with perl and try if it can give
me the same result of a small shell script i wrote a little while ago
but it doesnt seems to work out with me . here is my shell script

#!/bin/bash
DIRECTORY="/usr/bin"
for file in $DIRECTORY/*
do whatis `basename $file`

done
exit 0

i tried to run a similiar perl code by typing on command line.

perl -e "system qw (whatis /usr/bin/*)"

but its not giving me the same whatislog - what am i doing wrong ?

You are using the qw operator. This operator takes a space-separated
list of barewords and returns a quoted list of words. That is, your
system() call is equivalent to:
system('whatis', '/usr/bin/*');

When you call system() with two or more arguments, Perl executes the
first argument directly, passing in the remaining arguments. It does
not spawn a shell at all. So the * in the second argument there is
not interpreted by any shell to mean "all files", because there is no
shell to do the interpreting. So you are litterally calling "whatis"
on the single argument "/usr/bin/*". Since no such file with that
name exists, there is no output.

Change your qw() to qq() or q(), and read up on `perldoc -f system`
for more information.

Paul Lalli
 
E

elsiddik

You are using the qw operator. This operator takes a space-separated
list of barewords and returns a quoted list of words. That is, your
system() call is equivalent to:
system('whatis', '/usr/bin/*');

When you call system() with two or more arguments, Perl executes the
first argument directly, passing in the remaining arguments. It does
not spawn a shell at all. So the * in the second argument there is
not interpreted by any shell to mean "all files", because there is no
shell to do the interpreting. So you are litterally calling "whatis"
on the single argument "/usr/bin/*". Since no such file with that
name exists, there is no output.

Change your qw() to qq() or q(), and read up on `perldoc -f system`
for more information.

Paul Lalli








You are using the qw operator. This operator takes a space-separated
list of barewords and returns a quoted list of words. That is, your
system() call is equivalent to:
system('whatis', '/usr/bin/*');

When you call system() with two or more arguments, Perl executes the
first argument directly, passing in the remaining arguments. It does
not spawn a shell at all. So the * in the second argument there is
not interpreted by any shell to mean "all files", because there is no
shell to do the interpreting. So you are litterally calling "whatis"
on the single argument "/usr/bin/*". Since no such file with that
name exists, there is no output.

Change your qw() to qq() or q(), and read up on `perldoc -f system`
for more information.

Paul Lalli

well i tried running the code with q and qq but im still getting the
same output --
the part that i cant understand is when you run the shell script - i
could see all the /usr/bin/files output with <whatis> details ,
with perls everything looks quiet good also but instead of the
<whatis> details - keeps giving me /usr/bin/filename: nothing
appropriate.

here is an outlook:

animate (1) - animates an image or image sequence on any
X server << shell script
animate: nothing appropriate.

i even tried to write a perl script - used File::Basename

<code>

#!/usr/bin/perl -w

use strict;
use warnings;

use File::Basename;

my $path = "/usr/bin/";
my $files = basename($path);
my $dir = dirname($path);

print "dir is $dir , files is $files\n";

system "whatis $path";

</code>

im keep having the same log :x

its confusing me big time.

cheers,

zaher el siddik
http://elsiddik.blogspot.com/
 
K

Klaus

well i tried running the code with q and qq
my $path = "/usr/bin/";
system "whatis $path";
its confusing me big time.

It's confusing you, probably because you forgot to put an asterisk at
the end of /usr/bin/
 
P

Paul Lalli

well i tried running the code with q and qq but im still getting the
same output --

I don't believe you. Please post a short-but-complete script that
demonstrates this, like so:

$ perl -e'system qq(whatis /usr/bin/*)'
acctcom acctcom (1) - search and print process accounting
files
activation-client activation-client () - bonobo-
activationdebugging tool
adb adb (1) - general-purpose debugger
the part that i cant understand is when you run the shell script - i
could see all the /usr/bin/files output with <whatis> details ,
with perls everything looks quiet good also but instead of the
<whatis> details - keeps giving me /usr/bin/filename: nothing
appropriate.

Again, post a short-but-complete script that generates this output.
i even tried to write a perl script - used File::Basename

I have no idea what you think File::Basename has to do with this.
<code>

#!/usr/bin/perl -w

use strict;
use warnings;

use File::Basename;

my $path = "/usr/bin/";
my $files = basename($path);
my $dir = dirname($path);

I still have no idea what you think File::Basename has to do with
this.
print "dir is $dir , files is $files\n";

Didn't that output tell you you're doing something very wrong? It
should have claimed that $dir is /usr and $files is the empty string.
system "whatis $path";

Now you're just calling whatis on "/usr/bin/", rather than on all the
files in /usr/bin. Why did you omit the * this time?

Paul Lalli
 
E

elsiddik

I don't believe you. Please post a short-but-complete script that
demonstrates this, like so:

$ perl -e'system qq(whatis /usr/bin/*)'
acctcom acctcom (1) - search and print process accounting
files
activation-client activation-client () - bonobo-
activationdebugging tool
adb adb (1) - general-purpose debugger


Again, post a short-but-complete script that generates this output.


I have no idea what you think File::Basename has to do with this.






I still have no idea what you think File::Basename has to do with
this.


Didn't that output tell you you're doing something very wrong? It
should have claimed that $dir is /usr and $files is the empty string.


Now you're just calling whatis on "/usr/bin/", rather than on all the
files in /usr/bin. Why did you omit the * this time?

Paul Lalli


i could solve it with :
perl -e 'chdir (shift || "/usr/bin"); system whatis => <*>'

thx anyway guys

zaher elsiddik
http;//elsiddik.blogspot.com/
 
P

Peter J. Holzer

well i wanted to just mess a little with perl and try if it can give
me the same result of a small shell script i wrote a little while ago
but it doesnt seems to work out with me . here is my shell script

#!/bin/bash
DIRECTORY="/usr/bin"
for file in $DIRECTORY/*
do whatis `basename $file`

done
exit 0

i tried to run a similiar perl code by typing on command line.

perl -e "system qw (whatis /usr/bin/*)"

but its not giving me the same whatislog - what am i doing wrong ?

Your perl script doesn't do the same thing as your shell script.

Your shell script loops over all the filenames matching /usr/bin/*,
extracting the basename of each and calling whatis with that. So if your
/usr/bin/* starts like this:

/usr/bin/822-date
/usr/bin/Mail
/usr/bin/X
/usr/bin/X11
/usr/bin/Xorg
/usr/bin/[
/usr/bin/a2p
/usr/bin/aconnect
/usr/bin/acpi
/usr/bin/acpi_fakekey

it will invoke

whatis 822-date
whatis Mail
whatis X
...

Your perl script just invokes the shell with the command
"whatis /usr/bin/*" (assuming qq instead of qw), which will will in turn
invoke

whatis /usr/bin/822-date /usr/bin/Mail /usr/bin/X /usr/bin/X11 ...


hp
 

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

Forum statistics

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

Latest Threads

Top