Computing.Net > Forums > Unix > If statement paramenter checking

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

If statement paramenter checking

Reply to Message Icon

Name: ronw1
Date: December 7, 2008 at 09:06:48 Pacific
OS: UNIX
CPU/Ram: n/a
Product: N/a / N/A
Comment:

Hello I am tring to write script for my computer class and having some trouble with an if statement checking a paramenter is true or false and then displaying files.
I need user to enter a menu choice and their username. this will display the contents of their home directory. if user doesn't enter anything it will display the current users home directory. here is my code. I sure hope you can help. Trying to check that $1 has something in it.
#!/bin/csh
#12/6/2008
#CISS 125-70
#1
# display all files in user's home directory

clear
if (test \$1\ = \\) then
ls ~
endif
#ls /home/$1
sleep 5
menu




Sponsored Link
Ads by Google

Response Number 1
Name: Curt R
Date: December 9, 2008 at 07:38:13 Pacific
Reply:

What are the available menu options?

I recently did a UNIX course myself and had a similar question to what you're talking about and here's my script:

****Begin Script****

#!/bin/ksh
clear
while [ "$option" != "q|Q" ]
do
echo "Use one of the following options:"
echo " d: To display today's date and present time"
echo " l: To see the listing of all files in your present working directory"
echo " w: To see who's presently logged in"
echo " q: To quit this program"
echo "Enter your option and hit <Enter>: \c"
read option
echo
case "$option" in
d|D) date
;;
l|L) ls -ilSF
;;
w|W) who
;;
q|Q) echo "Exiting program...."
echo
echo
exit 0
;;
*) echo "Invalid option, try your command again"
esac
echo
echo
echo -n "hit CR to continue : "
read X
clear
done
exit 0


****End Script****

This is actually the end result after the text (and course) built
on the original script which just performed one task and exited. I got playing around
with it, tossed it in a 'while' loop and then the next step in the book was to do just that.

You'll notice it error checks for incorrect key entries and will
work with either a lower case entry or an upper case.

The directory listing command just lists the files in the present working directory.
I'm sure you can figure out how to make it show what's in the home directory.

I hope this points you in the right direction.



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: If statement paramenter checking

IF statements Comparing variables www.computing.net/answers/unix/if-statements-comparing-variables/6628.html

if statement www.computing.net/answers/unix/if-statement/6676.html

While read is ignoring if statement www.computing.net/answers/unix/while-read-is-ignoring-if-statement/7435.html