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

Hi, i have written a shell script to run various perl scripts. My problem is that although all the scripts run perfectly, the final script requires a response from the user , e.g they have to type a number to see the results. The shell script doesn't like this and prints 'error unrecognised command' when a number is typed. How can i get around this. (code is too long to include) :-)

Replies are listed 'Best First'.
Re: shell scripts + user response
by Abigail-II (Bishop) on Jul 16, 2002 at 12:14 UTC
    I've never heard of a shell that doesn't like that, nor of a shell that has "error unrecognised command" as an error message. And it isn't a Perl error either.

    Are you sure the problem is with the shell? In that case, you should probably go to a newsgroup discussing the shell you are using. Or could it be that it's actually the program that is generating is error message?

    Abigail

Re: shell scripts + user response
by derby (Abbot) on Jul 16, 2002 at 12:51 UTC
    AM,

    I agree with Abigail and as a point if the code is too long to include here than your trying to do too much at once. Are you able to reduce the long code to a much shorter version that also replicates the problem? You may find that exercise will help you fix the problem. If you're able to reduce and still not find the answer, then re-post with the shorter version.

    -derby

Re: shell scripts + user response
by graff (Chancellor) on Jul 17, 2002 at 05:49 UTC
    Are you limited to just editing the shell script, or can you change the perl script in question as well?

    At the point when you start the shell script, do you already know what numeric value you want to supply to the final perl script?

    Is there a compelling reason to use a shell script to invoke all those perl scripts, as opposed to using a perl script to run them all?

    If you can modify the final-step perl script in the set, and if you know the value you want before you start the shell script, make that last perl script look for a command-line arg to get its numeric value, and supply it up front when running the shell script.

    Better yet, use Perl instead of shell to run everything, and in the case of the last script, start it like this:

    open(LAST, "|last_script.pl"); print LAST "$numeric_param\n"; close LAST;
    This way, at whatever point is suitable before running this last step, you can assign a suitable value to $numeric_param, using whatever perl input method suits you (hard coded, command-line arg, user input on stdin, reading results of some previous step in the chain, checking localtime, ... or any combination thereof), and you don't have to edit that particular perl script, either.