Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

shebang problem on openSUSE

by kcott (Archbishop)
on Mar 24, 2018 at 00:22 UTC ( [id://1211643]=perlquestion: print w/replies, xml ) Need Help??

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

I encountered a problem with the shebang line using openSUSE.

For testing purposes, I narrowed this down to one of the simplest of scripts (test_shebang.pl):

#!/usr/bin/env perl -l print 'Hello, world!';

When I attempt to run this, I get:

ken@ibm-laptop:~/tmp> test_shebang.pl /usr/bin/env: perl -l: No such file or directory

It's not a $PATH or permission issue:

ken@ibm-laptop:~/tmp> echo $PATH <list of unrelated paths>:. ken@ibm-laptop:~/tmp> which test_shebang.pl /home/ken/tmp/test_shebang.pl ken@ibm-laptop:~/tmp> ls -l test_shebang.pl -rwxr-xr-x 1 ken users 48 Mar 24 10:29 test_shebang.pl

I've checked for any problematic characters that might have been present, but found none:

ken@ibm-laptop:~/tmp> cat -vet test_shebang.pl #!/usr/bin/env perl -l$ $ print 'Hello, world!';$ $

When changing the shebang line to any of the following, the scripts run with expected output (i.e. prints "Hello, world!" with or without "\n"):

#!/usr/bin/env perl #!/usr/bin/perl -l #!/usr/bin/perl

The '-l' switch appears to work correctly from the command line:

ken@ibm-laptop:~/tmp> perl -e 'print "Hello, world!"' Hello, world!ken@ibm-laptop:~/tmp>
ken@ibm-laptop:~/tmp> perl -le 'print "Hello, world!"' Hello, world!

The platform is "openSUSE Leap 42.1" and the Software Updates notification is telling me "Your system is up to date" (after running "Check For Updates"). Other relevant info:

ken@ibm-laptop:~/tmp> perl -v | head -2 | tail -1 This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi ken@ibm-laptop:~/tmp> uname -a Linux ibm-laptop 4.1.34-33-default #1 SMP PREEMPT Thu Oct 20 08:03:29 +UTC 2016 (fe18aba) x86_64 x86_64 x86_64 GNU/Linux

I'm using a borrowed laptop (the owner is not currently contactable) and I'm not overfamiliar with openSUSE: perhaps I just need to tweak a setting. Neither Super Search nor Internet searches have proved fruitful.

Any help would be appreciated.

— Ken

Replies are listed 'Best First'.
Re: shebang problem on openSUSE [additional tests]
by kcott (Archbishop) on Mar 24, 2018 at 06:23 UTC

    I ran some additional tests to what I showed in the OP and in Re^2: shebang problem on openSUSE:

    ken@ibm-laptop:~/tmp> /usr/bin/env perl -e 'print "Hello, world!"' Hello, world!ken@ibm-laptop:~/tmp>
    ken@ibm-laptop:~/tmp> /usr/bin/env perl -le 'print "Hello, world!"' Hello, world!
    ken@ibm-laptop:~/tmp> which env /usr/bin/env
    ken@ibm-laptop:~/tmp> env perl -e 'print "Hello, world!"' Hello, world!ken@ibm-laptop:~/tmp>
    ken@ibm-laptop:~/tmp> env perl -le 'print "Hello, world!"' Hello, world!
    ken@ibm-laptop:~/tmp> env perl -l -e 'print "Hello, world!"' Hello, world!
    ken@ibm-laptop:~/tmp> env perl -e 1 ken@ibm-laptop:~/tmp>

    This all suggests that env is parsing its arguments correctly. While it doesn't provide an answer to the shebang issue I'm experiencing, it does perhaps narrow down the causes.

    — Ken

Re: shebang problem on openSUSE
by Anonymous Monk on Mar 24, 2018 at 10:30 UTC

      Thanks for digging that up. I've been traveling a lot over the last month or two, not always had access to computers and/or networks, and have missed many posts on this site.

      — Ken

Re: shebang problem on openSUSE
by Anonymous Monk on Mar 24, 2018 at 02:58 UTC

    A search on DuckDuckGo brings up some relevant results. There was some article/discussion on Perl specific resource, outside of Stack Overflow, but I cannot find or remember it.

    In env perl -1, env tries to find a file to execute named perl -l. It is not found, hence the error. OTOH perl -l parses the run time options by itself so there is no problem there.

      Thanks for replying.

      "A search on DuckDuckGo brings up some relevant results."

      That is, in fact, the search engine I used. Could you post the URL you used which returned the "relevant results". I seached for "shebang perl openSUSE", which ended up as this URL: https://duckduckgo.com/?q=shebang+perl+openSUSE&t=opensuse&ia=qa.

      I didn't see any results where 'perl -l' (or 'perl -w' or similar) was treated as a single filename containing a space character. As I wrote that, I thought I might try the same code as before with this shebang line:

      #!/usr/bin/env perl -w

      When run, that now produces:

      ken@ibm-laptop:~/tmp> test_shebang.pl /usr/bin/env: perl -w: No such file or directory

      I checked "man env" and subsequently, from the information it suplied, "info '(coreutils) env invocation'" and http://www.gnu.org/software/coreutils/manual/coreutils.html#env-invocation. All show an invocation of this form:

      env [option]… [name=value]… [command [args]…]

      As far as I can see, none mention anything special about the space after "command".

      I've been using shebang lines like this for over a decade. I would have posted dozens (if not hundreds) of scripts on this site using "#!/usr/bin/env perl -l" without a single complaint.

      If 'perl -l' is being interpreted as a single filename (containing a space character), that would be most unusual behaviour and I would hope there would be a way to turn it off.

      — Ken

      ... perl -l parses the run time options by itself ...

      I meant perl the interpreter parses the options, not perl -l.

Re: shebang problem on openSUSE
by Anonymous Monk on Mar 24, 2018 at 12:13 UTC
    env is also an ordinary console command ... that's why it works as a shebang ... so it has a man page and can also be tried-out directly on the command line in the shell.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1211643]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-20 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found