gudii9
asked on
perl example not runiing
hi,
i wrote simple perl script and trying to run geting below error from
https://www.tutorialspoint.com/unix_terminal_online.php
sh-4.4$ vi hi.pl
sh-4.4$ pwd
/home/cg/root
sh-4.4$ /home/cg/root/hi.pl
sh: /home/cg/root/hi.pl: Permission denied
i just wrote in hi.pl as
print "hii";
in command prompt of windows it ran fine once i install activevperl
https://www.activestate.com/activeperl/downloads
C:\Users\ss\perl\code>perl hello.pl
hii
please advise
i wrote simple perl script and trying to run geting below error from
https://www.tutorialspoint.com/unix_terminal_online.php
sh-4.4$ vi hi.pl
sh-4.4$ pwd
/home/cg/root
sh-4.4$ /home/cg/root/hi.pl
sh: /home/cg/root/hi.pl: Permission denied
i just wrote in hi.pl as
print "hii";
in command prompt of windows it ran fine once i install activevperl
https://www.activestate.com/activeperl/downloads
C:\Users\ss\perl\code>perl
hii
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have below content in file just one line
print "hii";
print "hii";
Add the following as the first line in hi,pl
#!/usr/bin/perl
to make hi.pl look like (vi hi.pl
now run it, ./hi.pl
and you should see
hi
as the output.
#!/usr/bin/perl
to make hi.pl look like (vi hi.pl
#!/usr/bin/perl
print "hi\n";
now run it, ./hi.pl
and you should see
hi
as the output.
ASKER
now i see output
sh-4.4$ vi hi.pl
sh-4.4$ ./hi.pl
hish-4.4$
what is meaning of below line
#!/usr/bin/perl
my perl script not at above location but at brlow location
sh-4.4$ pwd
/home/cg/root
please advise
sh-4.4$ vi hi.pl
sh-4.4$ ./hi.pl
hish-4.4$
what is meaning of below line
#!/usr/bin/perl
my perl script not at above location but at brlow location
sh-4.4$ pwd
/home/cg/root
please advise
Refereñce your Windows example
Your script, hi.pl is in the location reflected by pwd, the interpreter, perl is located in /usr/bin/perl
The first line tells the shell (environment in your case it is bash) where the interpreter that will process the script is.
Run the command,
which perl
This will tell your the command for perl is.
Your script, hi.pl is in the location reflected by pwd, the interpreter, perl is located in /usr/bin/perl
The first line tells the shell (environment in your case it is bash) where the interpreter that will process the script is.
Run the command,
which perl
This will tell your the command for perl is.
ASKER
sh-4.4$ which perl
/usr/bin/perl
is above is path where perl library is inatalled?
do we need to refer that in everu perl script i write at top?
who installed there tutoralpoint guys?
https://www.tutorialspoint.com/unix_terminal_online.php
i just instaled on windows laptop only
/usr/bin/perl
is above is path where perl library is inatalled?
do we need to refer that in everu perl script i write at top?
who installed there tutoralpoint guys?
https://www.tutorialspoint.com/unix_terminal_online.php
i just instaled on windows laptop only
Yes, unix, Linux scripts have to include the interpreter to be used to process the script as the first line
Note # means it is a comment
!/usr/bin/perl means use this executable.
At times shell script using sh, bash, ksh, zsh tcsh might be processed by the shell in which the person is
I.e. While first line says /bin/sh bash as the environment might process the script.
There are times where a script should be processed in a specific way, and to make sure one is directed to explicitly run
<shell> shell_script
Similar to the perl hi.pl you ran under Windows and can run under UNIX/Linux.
Note # means it is a comment
!/usr/bin/perl means use this executable.
At times shell script using sh, bash, ksh, zsh tcsh might be processed by the shell in which the person is
I.e. While first line says /bin/sh bash as the environment might process the script.
There are times where a script should be processed in a specific way, and to make sure one is directed to explicitly run
<shell> shell_script
Similar to the perl hi.pl you ran under Windows and can run under UNIX/Linux.
ASKER
sh-4.4$ vi hi.pl
sh-4.4$ pwd
/home/cg/root
sh-4.4$ /home/cg/root/hi.pl
sh: /home/cg/root/hi.pl: Permission denied
sh-4.4$ chmod 700 hi.pl
sh-4.4$ /home/cg/root/hi.pl
/home/cg/root/hi.pl: line 1: print: command not found