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

Please put down the flame throwers and pitchforks momentarily.
I have read the standard methods to perform this old trick.
They just don't work on the new Ubuntu 15.10.


Goal:

Get ~/bin/psr.pl et al. to run as just psr Perl Search-n-Replace


Method:

Add ~./bin to $ENV{PATH}
Add shebang line pointing to /usr/local/bin/perl (5.22.1)
Tried aliasing /usr/bin/perl to /usr/local/bin/perl, broke apt-get
gave psr.pl 744 permissions, owned by me
running /bin/bash shell


Result:

psr.pl works fine, psr -> No command 'psr' found, did you mean:

Limparound (can't fail!):

Create ~/bin/psh dir
create psr.sh wrapper for psr.pl (modeled after horrible dos)
Place psh directory ahead of ~/bin in path
run psr.sh to get to psr.pl
result => SNAFU



TEST CASE:

]] SORRY FOR NANO-)CODE( SIZE [[ brianp@raptor:~$ eng path [[ env | grep -i => check PATH]] PATH=/home/brianp/bin/psh:/home/brianp/bin:/usr/local/sbin:/usr/local/ +bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games brianp@raptor:~$ fcmd.pl psr [[ Search $ENV{PATH} for target ]] /home/brianp/bin/psh/psr.sh /home/brianp/bin/psr.pl brianp@raptor:~$ ll `fcmd.pl psr` [[ Check paths and exec perms ]] -rwxr--r-- 1 brianp brianp 62 Jan 30 11:30 /home/brianp/bin/psh/psr.s +h* -rwxr--r-- 1 brianp brianp 217 Sep 5 2001 /home/brianp/bin/psr.pl* brianp@raptor:~$ cat `fcmd.pl psr` [[ check for [more] buggy code ] +] #!/bin/sh /usr/local/bin/perl -w /home/brianp/bin/psr.pl "$@" ... #!/usr/local/bin/perl -w # PSR - Perl Search & Replace. Replacement for the #%%&^*# braindead s +ed. $target = $ARGV[0]; # Target to search for is the first argument. for(<STDIN>) { eval $target; print $_; } [[ Check for actual functionality... Filter BLANK lines ]] brianp@raptor:~$ /usr/local/bin/perl -v | psr.sh "s/^\s*$//" | head -n + 2 This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-li +nux Copyright 1987-2015, Larry Wall [[ psr.sh does filter top blank line! + ]] brianp@raptor:~$ /usr/local/bin/perl -v | head -n 2 [[ blank line starts spew ]] This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-li +nux brianp@raptor:~$ /usr/local/bin/perl -v | psr.pl "s/^\s*$//" | head -n + 2 This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-li +nux Copyright 1987-2015, Larry Wall [[ blank line gone, Larry's Baaaaaaaa +k ]] brianp@raptor:~$ psr 2>&1 | head -n1 No command 'psr' found, did you mean: brianp@raptor:~$ whoami brianp brianp@raptor:~$ eng shell SHELL=/bin/bash brianp@raptor:~$ cat /etc/debian_version jessie/sid [[ Ubuntu 15.10 -> Wily Werewolf ??] brianp@raptor:~$ uname -a Linux raptor 4.2.0-25-generic #30-Ubuntu SMP Mon Jan 18 12:31:50 UTC 2 +016 x86_64 x86_64 x86_64 GNU/Linux brianp@raptor:~$ ll /bin/sh [[ Not regular sh/bash]] lrwxrwxrwx 1 root root 4 Jan 22 23:48 /bin/sh -> dash* [[ shell made by iceholes to confound infidles? ]] brianp@raptor:~$ ll `which dash` -rwxr-xr-x 1 root root 125400 Jun 4 2015 /bin/dash*

Confounded for sure! ============================================ 1nickt, >> Why do you think you can execute the program without using its full name?
A) it's in the path,
B) It has exec permissions
C) the `file` command identifies it as an 'ASCII text exec'
C.5) The #! line tells it everything it needs
D) if it works on dos, it has to work on *_Linux_*! Surely!!
E) Slick sys admins use magic to keep the .pl ext
and make it run like *.exe on win; works just the
same with/without the .exe. Standard Practice! F) Linux does not care about file extensions G) The simple procedure for .sh is well documented:
http://stackoverflow.com/questions/2999448/executing-shell-script-without-calling-sh-implicitly

Maybe they used links. This can not be a hard cat to skin!!!
If you ask your "intelligent assistant" to run "psr",
which is a more satisfactory response:
"HUH???" or
"I'll Pounce on psr.pl, STAT!"

I have had the convenience at numerous contracts,
I have it now on windoz.
I shall have it on my new, WizBang Workstation if I
have to hack the Kernel to the nub in the process.

brianp@raptor:~$ file `fcmd.pl psr` /home/brianp/bin/psh/psr.sh: POSIX shell script, ASCII text executable /home/brianp/bin/psr.pl: a /usr/local/bin/perl -w script, ASCII te +xt executable, with CRLF line terminators

Replies are listed 'Best First'.
Re: Perl script w/o .pl extension broken on Ubuntu?
by 1nickt (Canon) on Jan 30, 2016 at 20:03 UTC
    "psr.pl works fine, psr -> No command 'psr' found, did you mean:

    Why do you think you can execute the program without using its full name? All the stuff you mentioned about changing your PATH and file permissions will be immaterial if you try to run a file that doesn't exist.

    Have you tried renaming the script as psr and running that?

    (You don't need the script file to end in a particular extension for Perl to be able to run it ...)

    The way forward always starts with a minimal test.
      It's the old LINK TRICK!

      ln -s /home/brianp/bin/psr.pl /home/brianp/bin/psh/psr brianp@raptor:~$ perl -v | psr "s/^\s*$//" | head -n 2 This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-li +nux Copyright 1987-2015, Larry Wall PATHEXT=.BAT;.pl;.EXE;.COM;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY; +.PYW
      It's Alive!

      Forcing each user to either vitiate their script names or maintain
      a parallel link system with double maintenance is most inattentive!

      Fixing such a simple problem by destroying information and abolishing
      file extensions just seems wrong-headed. Perhaps, it's the NIH syncrom;

      How about (ba)sh feature: EXEC_EXTENSION=pl:sh:py:rb ExExt?

      Having the ability to specify execution preference based not only
      on directory but also on EXTension is very handy.

      Rather like Intermittent Windshield Wipers!
      Once you have used them, they are hard to do without.

      Ford never put them on the Model T so YOU CAN'T HAVE THEM!
      How can you have your wipers both ON and OFF at the Same Time?
      That's Just Crazy!!!
      Have you tried REMOVING YOUR WINDSHIELD TO FIX THE PROBLEM?? :-)

      This is NOT a PERL PROBLEM. I was hoping that there was a
      GOOD PERL SOLUTION
      eval(($COMSPEC($cmd)) =~ m/BAD COMMAND/i) && exec(&fcmd($cmd))[0]) *!!!

      NOTE* Concept only, do not run, may fuse your North Bridge!

Re: Perl script w/o .pl extension broken on Ubuntu?
by GotToBTru (Prior) on Jan 30, 2016 at 22:57 UTC

    Recognize that DOS is doing some work behind the scenes. When you give it a command that isn't part of its list, it starts to look for filenames that match, using a variety of file extensions (.bat, .exe, .com). Failing that, it looks in directories in the path, etc.

    Unix isn't DOS.

    Update: read this. Note that none of the steps involve adding an extension to the file if you don't supply one.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: Perl script w/o .pl extension broken on Ubuntu?
by jcb (Parson) on Jan 31, 2016 at 02:25 UTC

    I normally use symlinks for extensionless names for scripts. In your case, with psr.pl in ~/bin, try:

    cd ~/bin ln -svi psr.pl psr

    This creates a symbolic link psr for the shell to find when it goes looking for commands. If you currently can run psr by entering psr.pl, then this will fix your problem.