Register
It is currently Sat Apr 19, 2014 11:01 am

!!! Help !!! Script help for my college final due 12pm PST


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sat Dec 10, 2011 10:00 pm   

Joined: Sat Dec 10, 2011 9:50 pm
Posts: 1
Hi all,

I need some help on my college final. Im writing a script with how it runs set by my instructor. I have written part of the script and it works but I cannot get his last request implemented and running correctly. Below is the code I have written so far.

-------------
date=`date +%d\ %B\ %Y`
whoami=`whoami`
hostname=`hostname`


if [ $# -eq 0 ]
then
echo "Usage: $0 options arguments"
echo "Enter one or more options or arguments."
exit 1
fi

while [ $# -gt 0 ]
do
case "$1" in
-w) echo "$whoami"
;;
-d) echo "$date"
;;
-h) echo "$hostname"
;;
-help) echo "
valid options:

-d = display todays date in dd Month YYYY format
-h = display computer system name you are working on.
-w = display who you are logged in as.

Any argument entered is checked to see if it is a file name.
"
;;
*) echo "$1 is an unknown option."
;;
esac
shift
done

---------------

This is what Im missing...

For any other options, display the following error message:

"$1 is an unknown option"

- For every word on the command line that is not an option, I want you to determine if the word (argument) is a file name. If the word (argument) is a file name then display the following message.

"$1 is a file"

If the word (argument) is not a file then display the following message.

"$1 is not a file"

Please Help!!!


Top
 Profile  
 PostPosted: Sun Dec 11, 2011 8:38 am   
User avatar

Joined: Sat Jul 02, 2011 10:43 am
Posts: 23
Location: Devon,UK
use the *) as the last case statement, this will catch every thing, also just use the file test construct ie
Code:
if [ -f "variable conating a posible file path" ];then
do somthing cos its a real file
else
its not a real file so do somthing else
fi
you might want to get hold of the advanced BASH scripting guide (abs) just google it
P.S.
This belongs in requests not the sandbox


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP