Hello LinuxQuestions world!
I'm still pretty new to linux, and burning through a unix/linux course offered at the local JC. I'm working on an assignment for shell scripting and I need to make a script that displays a bunch of junk (pwd, date, yadda yadda) and then prompts the user to enter a directory so they can view the contents. If it's valid, then it displays the contents. If it isn't then it throws an error message and the script stops. This is done using if, then and else.
The problem is, my script always shoots straight to the else, even if the subdir entered IS a valid subdirectory.
Here's what I have:
Code:
clear
pwd
echo Today is 'date +%m/%d/%y'
date +%r
echo "Which Subdirectory would you like to display?"
read subdir
if test -d $subdir
then
ls /cs41s1003/$subdir
else
echo "Sorry, $subdir is not a valid subdirectory! Give it another shot!"
fi
When I run the the script
I get:
Code:
/home/cs41s1003/Assignment-3
Today is date +%m/%d/%y
09:42:26 PM
Which Subdirectory would you like to display?
Assigment-3
Sorry, Assigment-3 is not a valid subdirectory! Give it another shot!
[cs41s1003@cc-ccs Assignment-3]$
Can anyone give me a heads up about what I'm fudging here?
Also, cs41s1003 is my "home" folder for the class on our linux server, which is a subdir of home. (home/cs41s1003/Assignment#/yadda/yadda)
Thanks!
Tristan