Avatar of gudii9
gudii9Flag for United States of America

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
LinuxLinux NetworkingPerlUnix OSLinux Distributions

Avatar of undefined
Last Comment
arnold
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

now is ee below error with print


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
Avatar of gudii9
gudii9
Flag of United States of America image

ASKER

i have below content in file just one line

print "hii";
Avatar of arnold
arnold
Flag of United States of America image

Add the following as the first line in hi,pl
#!/usr/bin/perl

to make hi.pl look like (vi hi.pl
#!/usr/bin/perl
print "hi\n";

Open in new window


now run it, ./hi.pl
and you should see
hi
as the output.
Avatar of gudii9
gudii9
Flag of United States of America image

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
Avatar of arnold
arnold
Flag of United States of America image

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.
Avatar of gudii9
gudii9
Flag of United States of America image

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
Avatar of arnold
arnold
Flag of United States of America image

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.
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo