Tough question - interactive prompts

I have inherited a script (ksh) - which requires an input file and location to be specified on the command line.....

i.e runsc MRG_060601 ../input_files/

I am trying to tidy this up by using an env variable for the location (as it is always the same) - but it will still require the name of the input file to run.

There are two things I want to do:

  1. I want to be able to run multiple files from within the $LOAD
    directory (my new env variable)...i.e runsc $LOAD/*

Should I do this with a for loop? Or is there a prettier way?

  1. I want to write an auto-complete function that reads each character as it is entered and scans the $LOAD dir to see if it can finish the filename. (similar to bash).

So I could just type "runsc" - then when prompted start by typing..."MR" and the line would be completed for me if there was only one thing it could be - or completed as far as possible if there are multiple matches with different endings.

I imagine this is a single character read type thing - but i don't want to go to the hassle of writing a convoluted script if there is a function existing - or a nice tody method.

Full or part answers appreciated.

:confused:

I've got this that works for running through each file in the $LOAD directory. I've also changed the script so that it looks by itself for the $LOAD directory (which I am setting with a setenv type file taht gets run at the start).

for x in $LOAD/*
do
do my stuff here
mv $x to PROCESSED directory
done

Works..and the movement is for my use (not because it's requierd) - seems simple - works - quite efficient.....no better way though?

I like your approach the best. The script automatically files input files and consumes as it finishes. The only change I would make is building LOAD into the script so it's not dependent on an environment variable.

You can also do something like:

#! /usr/bin/ksh
for i ; do
     echo $i
done
exit 0 

A "for" loop like this is looping over the arguments to the script. You invoke this from yor favorite interactive shell that has filename completion capabilities.

But you don't want scripts to have their own custom filename completion code. After you have 100 scripts, each a little different, it's a nightmare. And if you go on vacation your assistant has a steep learning curve with even one such script. But if you use ksh and he uses tcsh, you both can use the command completion system that you know with the simpler approach.