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