I am trying to create a Unix script that when ran will provide a veiw of the files of the week that the user inputs, I have this one down. Then I would like them to be able to type in one of the files that is in that week and it displays that file. The script that I have keeps looping the week number until I hit q for quit and then it asks the user the name of the file they want to view, but does not display the contents. Some help would be appreciated. Thank you.
Course: POS 420/University of Phoenix
Code that I have been working with:
echo author : Goob
date
echo "Please enter week number (1-3) or q to quit"
read num
while test $num ! =q
do
if [ $num -lt 4 ]
then echo "The files submitted in week $num are:"
ls /mnt/sdb1/week$num/file*
else echo "Incorrect week number!"
fi
echo "Please enter file name from chosen week"
read file
while test $file != q
do
if [ -f /mnt/sdb1/week$num/$file ]
then echo "The contents of file $file are:"
cat /mnt/sdb1/week$num/$file
break
else read -p "Incorrect file name! Please select again or enter q:" file
fi
done
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Question: In your first while loop, you write "ls /mnt/sdb1/week$num/file*"
Is the user expected to type "file" as part of the filename?
i.e. your cat in the second while is "cat /mnt/sdb1/week$num/$file"
So to see file "whatever", I'd have to type "filewhatever".
If the file is not being displayed, either there is an error, or the follow on prompt "Incorrect filename ... Please select again.... " would be given. Is it?