943,740 Members | Top Members by Rank

Ad:
May 5th, 2009
0

You could have done it better, but how?

Expand Post »
Hi. I have created a script that works perfect but I am now told that I could have done it better, but how?
This is an example of how I did mine:

#!/bin/bash
#
function users
{

echo "1. Password file"
echo
echo "Enter num: "

read usernumber

if [ $usernumber -eq 1 ]
then
cat /etc/passwd

else if [ $usernumber -eq 2 ]
then
cat etc/passwd
fi
fi
I have been told that I shouldn't have done it using else if but what other ways are there of doing it?

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scottyscotty19 is offline Offline
22 posts
since Nov 2008
May 5th, 2009
0

Re: You could have done it better, but how?

Well you could have used code tags.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 5th, 2009
0

Re: You could have done it better, but how?

Hmm... Is that the whole script? I'm not seeing the "users" function called anywhere, or even a terminating "}" for the function

-G
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008
May 6th, 2009
0

Re: You could have done it better, but how?

The script here was just a quick example anyway I have sorted it I replaced if and else if with case.
Last edited by scottyscotty19; May 6th, 2009 at 6:54 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
scottyscotty19 is offline Offline
22 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Testing for date in files?
Next Thread in Shell Scripting Forum Timeline: sed -f clears the file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC