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

Please help me with this script... :confused:

Is this homework?

Franklin,
I am way too old for homework but I could use the same script for housekeeping ... just too stupid to write it myself and too lazy to do it manually :slight_smile:

Rgds
zxmaus

Needs a precise definition of a "C program" file on the OP's server and a good overview of the directory structure and permissions.

The implication is that a non-root users will run a root script which displays the header of each "C program" source under their control and then prompts them to decide whether to delete that program source. Should they provide filename(s) as parameters to the script, the script will then only prompt the user to delete those named files.

(I'm backing off on this one because the requirement is much too vague).

The main problem Im facing with this question is how to make the program pick up a C program in case no command line arguments are specified .

Code :

ls -lrt *.C 

Please elaborate it .

Hi rits,
As this is homework, we won't give you a full solution, just tips and help on very specific problems within your question. Try to break it down into exactly where you are stuck, and show what you have done so far if you want help with the overall outline.

Your 'ls' command looks like it should do what you want but try leaving out the 'l' flag as I don't think you actually need to care about the dates and permissions of the files, just the first 10 filenames.

The manual pages do a very good job of elaborating that command.

man ls
info ls

So I'd recommend you spend some time reading the manual pages or a good Unix/Linux book before rushing off to ask a question like that.

tyler_durden

ok , so here's what I have done so far :-

if[$# -eq 0]
then
for i in *.C
do
head input*.C > file.txt
cat > file.txt 
echo Do you want to delete this file ? (Y/N)
read answer
if test{$read -eq Y} then
rm $file.txt
fi
done

elfi[$# -ne 0]
then
echo|head $#
echo Do you want to remove the file? (Y/N)
read ans
if test{$read -eq Y} then
rm $#
fi
else 
echo "Invalid Argument"
fi

Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

Thank You.

The UNIX and Linux Forums.