sh: 1: program not found

22,370

There are two things that might be issues here. First, with the single-quoted string, the variable is not expanded, so the system() call sees the literal string procheck $proc 2.0. Since it contains a character special to the shell (the $), Perl runs the command through the shell, so the shell gets a chance to expand that. Unless your environment contains the variable proc, that will expand to nothing. But that doesn't matter much, since the shell can't even seem to find the program procheck in the PATH. It complains about that.

If we change the quotes to double-quotes, the variable gets expanded by Perl (which is probably what you want, since you're using that variable in the loop). But then you're likely get a warning from Perl about not being able to find procheck.

The solution to that is to give the full path to the program, or make sure it's in the scripts PATH.

Though if running it on an interactive shell works, it's possible that procheck is actually an alias or a function. If it's just a regular executable, it would be in the PATH, which should be inherited to Perl and the subshell. In e.g. Bash, you could use type -a procheck to see what it actually runs and if there are other alternatives, like a disk file masked behind an alias.


Oh, also, if you don't need the shell when running the command, you can prevent Perl from even accidentally calling it by using the list form of system and giving the arguments to the command as separate arguments to system. Here, that would be system("procheck", $proc, "2.0").

Share:
22,370

Related videos on Youtube

s kumar
Author by

s kumar

Updated on September 18, 2022

Comments

  • s kumar
    s kumar over 1 year

    I have written a script to execute files one by one by calling a installed program. The same program is executing from terminal, like procheck abc.pdb, then it's working fine. But when I execute this program in a Perl script like

    #!/usr/bin/perl -w
    @proc = glob '*.pdb';
    
    foreach $proc (@proc)
    
    {
         system ('procheck $proc 2.0');
    }
    

    Getting error

    sh: 1: procheck: not found 
    
    • Vlastimil Burián
      Vlastimil Burián over 6 years
      have you tried specifying the full path to procheck ?
  • Kusalananda
    Kusalananda over 6 years
    If the system() function can't find the procheck executable with double quotes, then it won't find it with single quotes either. This is not the problem that he OP is (currently) facing, but you're correct in that double quotes should be used to allow Perl to expand the $proc scalar.