You could have done it better, but how?

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 22
Reputation: scottyscotty19 is an unknown quantity at this point 
Solved Threads: 0
scottyscotty19 scottyscotty19 is offline Offline
Newbie Poster

You could have done it better, but how?

 
0
  #1
May 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
0
  #2
May 5th, 2009
Well you could have used code tags.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 61
Reputation: Gromit is an unknown quantity at this point 
Solved Threads: 7
Gromit's Avatar
Gromit Gromit is offline Offline
Junior Poster in Training

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

 
0
  #3
May 5th, 2009
Hmm... Is that the whole script? I'm not seeing the "users" function called anywhere, or even a terminating "}" for the function

-G
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 22
Reputation: scottyscotty19 is an unknown quantity at this point 
Solved Threads: 0
scottyscotty19 scottyscotty19 is offline Offline
Newbie Poster

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

 
0
  #4
May 6th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC