jkellington has asked for the wisdom of the Perl Monks concerning the following question:

this is really green. I am trying to give a script execute permission using chmod +x scriptname.pl the script is very simple, as follows: #!/usr/bin/perl print "Hello World!/n"; I do the chmod and it doesn't produce any errors, but when i type in "scriptname.pl" bash says it can't find the file. I've checked to make sure that the perl interpreter is indeed at /usr/bin/perl. Can someone tell me what I'm doing wrong? Please advise if questions like these are too "newbie" to be posted here. Thanks in advance, Jason

Replies are listed 'Best First'.
Re: extreme newbie question
by ZZamboni (Curate) on Apr 21, 2000 at 19:52 UTC
    This is not a Perl problem, but a shell problem.

    When you type a command in Unix with no path specification, the shell looks in the directories contained in your PATH environment variable to find it, and _only_ in those directories. If you come from the DOS world, this can be confusing because DOS looks in the PATH and by default it also looks in the current directory. Unix shells do not look in the current directory by default, you have to specifically add "." to your path ("." represents the current directory).

    So your problem is that "." is not in your PATH, so when you type "scriptname.pl" the shell does not find it. You can either type the path name explicitly:

    ./scriptname.pl
    or add "." to the end of your path:
    PATH=${PATH}:. export PATH scriptname.pl
    If you add "." to your path, make sure you add it at the end and not at the beginning. Adding it at the beginning can be a source for (at best) pranks and (at worst) security problems.
Re: extreme newbie question
by btrott (Parson) on Apr 21, 2000 at 10:57 UTC
    Try
    % ./scriptname.pl
    That "./" is necessary if you don't have '.' in your path.
      Thanks a lot. works great.
RE: extreme newbie question
by wallyworld2000 (Initiate) on Apr 21, 2000 at 21:46 UTC
    If the current directory "." is not in your PATH, you must do the following: ./scriptname.pl Check your current path with: echo $PATH
RE: extreme newbie question
by Anonymous Monk on Apr 21, 2000 at 17:41 UTC
    try perl -v this should print out version of perl if it does not then perl is not properly configured on your system or you do not have rights to excecute scripts.
RE: extreme newbie question
by Anonymous Monk on Apr 23, 2000 at 00:27 UTC
    It sounds like the current directory isn't in your path, they ./scriptname.pl. If that works you know your problem is a missing . in your path.
RE: extreme newbie question
by Anonymous Monk on Apr 21, 2000 at 17:43 UTC
    Try "./scriptname.pl" or even "perl scriptname.pl"
RE: extreme newbie question
by Anonymous Monk on Apr 21, 2000 at 19:11 UTC
    The /n you have at the end of your "Hello World" line should be a \n

    -DataTracer

RE: extreme newbie question
by jkellington (Acolyte) on Apr 22, 2000 at 07:24 UTC
    thanks for all your help. you guys deserve the monk moniker. jason