The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how i prepare a c++ code(c code) for implementing my own protocol format amitpansuria High Level Programming 1 09-06-2007 11:09 PM
IBM Takes Its Own Server Consolidation Medicine - IT Jungle iBot UNIX and Linux RSS News 0 08-07-2007 10:30 PM
IBM Takes Its Own Server Consolidation Medicine - IT Jungle iBot UNIX and Linux RSS News 0 08-02-2007 10:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-22-2007
misterpinkey misterpinkey is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 1
Code Consolidation

My code currently looks like this:

#!/usr/bin/ksh
clear

while true
do
clear

echo "Menu"
echo " 1. WPPHA1"
echo " 2. WPPHA2"
echo " 3. WPPHA3"
echo " 4. WPPHB1"
echo " 5. WPPHB2"
echo " 6. WPPHC0"
echo " 7. WPPHD0"
echo " 8. WPPHD1"
echo " 9. WPPHD2"
echo "10. WPPHD3"
echo "11. Exit"
echo

read choice
case $choice in
1)
clear
cp /usr/asm/data.1182/user_data/reticle_base/reticle_base /usr/asm/data.1182/user_data/reticle_base/reticle_base_temp
mv /usr/asm/data.1182/user_data/data_A01/user_data/reticle_base/reticle_base_temp /usr/asm/data.1182/user_data/data_A01/user_data/reticle_base/reticle_base
true
echo "Copy successful to WPPHA1"
read continue
$continue
clear
exit
;;

2)
clear
cp /usr/asm/data.1182/user_data/reticle_base/reticle_base /usr/asm/data.1182/user_data/reticle_base/reticle_base_temp
mv /usr/asm/data.1182/user_data/data_A02/user_data/reticle_base/reticle_base_temp /usr/asm/data.1182/user_data/data_A02/user_data/reticle_base/reticle_base
true
echo "Copy successful to WPPHA2"
read continue
$continue
clear
exit
;;

**it keeps doing this exact thing for all choices until 11, which just exits. The only differences for each choice are the things I highlighted in bold (the 3 characters which are short for the tool name & the echo prompt saying that the copy was successful. Is there a way to use a loop or something to consolidate this to make it smaller?

esac
done


Thanks,
MP
  #2 (permalink)  
Old 09-22-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by misterpinkey View Post
Is there a way to use a loop or something to consolidate this to make it smaller?
You could make each option a function, then have the case statement call each function for each option.

Or have each functions name be a prefix followed by a number, then read the number, append to the function prefix then call that.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0