Code Consolidation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Code Consolidation
# 1  
Old 09-22-2007
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  
Old 09-22-2007
Quote:
Originally Posted by misterpinkey
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

RRDtool consolidation not going as expected

Hello all, I am new to RRDtool and have made a RRDtool database with one data-source. Information of this data-source is stored in four different RRA's with different intervals for different time spans. Database create command: rrdtool create /root/mde.rrd --step 300 \... (2 Replies)
Discussion started by: ArtOfLosing
2 Replies

2. Shell Programming and Scripting

Apache Subnet consolidation script/routine help needed

I have a rather simple routine that I would like to fine tune. I am having scripters block if that exists. Trying to tally up that amount of subnets after I performed an awk and uniq from zipped apache logs. For instance, on a solaris 10 system: This does work gunzip -c access_log1.200834.gz |... (2 Replies)
Discussion started by: NYG71
2 Replies
Login or Register to Ask a Question