Tough question - interactive prompts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tough question - interactive prompts
# 1  
Old 02-18-2002
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?

2. 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.

Smilie
# 2  
Old 02-20-2002
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?
# 3  
Old 02-21-2002
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:
Code:
#! /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.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A very tough exercise

hello everyone!:) I have an exercise which I think is difficult for beginner like me. Here is the exercise Create a shell script, which takes a directory as command line argument. Script displays ten first lines from every text file in that directory. After displaying the lines from the... (1 Reply)
Discussion started by: googlevn
1 Replies

2. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

3. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

4. UNIX for Dummies Questions & Answers

tough parsing

I have a string as "Period= 20090531 Client Name= Clayton Lumbar Company Destination= MD" I want to parse the string and store it in 3 different variables. $period (should get value 20090531) $client (should get value "Clayton Lumbar company") $dest (should get value MD) How can I do... (3 Replies)
Discussion started by: paruthiveeran
3 Replies

5. UNIX for Advanced & Expert Users

Tough Substituion command

I have lines like: Mg2.qns W=0.175u Mg2.qpsb W=0.175u Mg4.qns W=0.175u Mg4.qpsb W=0.175u Which I need to become: Mg2.qns W=wmg2qns Mg2.qpsb W=wmg2qpsb Mg4.qns W=wmg4qns Mg4.qpsb W=wmg4qpsb To acheive this individually line by line I use a command like:... (3 Replies)
Discussion started by: ggggdddd
3 Replies

6. Programming

Tough makefile question

At my company, we build some stuff using a makefile. While the makefile script is running, a developer may check in a newer version of a source file. The problem is, when we next run the make command, the target file isn't rebuilt, because the date of the target is after the dependency. Any... (1 Reply)
Discussion started by: mbbeaubi
1 Replies

7. Shell Programming and Scripting

Seems the Shell Script is very tough

Guys plz respond. (1 Reply)
Discussion started by: prince_of_focus
1 Replies
Login or Register to Ask a Question