Help me streamline this counting part of my script.
Ok, so this is a small part of a script I wrote to build disk groups using VXVM. The only problem is that I am limited to a count of 8 maximum. If I want more, I will have to add more lines of "if" statements. How can I accomplish the same thing, in a few lines, but not be limited in the max count?
In this case, $NUMBER = 8
Code:
echo "There are $TOTAL2 $DISKTYPE disks of this size available."
echo
echo "How many do you want to use(8 disks max!)"
print -n "to create your diskgroup? :"
read NUMBER
if [ $NUMBER -eq 1 ]
then
continue
# exit
fi
if [ $NUMBER -eq 2 ]
then
alphabet="02"
count=0
fi
if [ $NUMBER -eq 3 ]
then
alphabet="02 03"
count=0
fi
if [ $NUMBER -eq 4 ]
then
alphabet="02 03 04"
count=0
fi
if [ $NUMBER -eq 5 ]
then
alphabet="02 03 04 05"
count=0
fi
if [ $NUMBER -eq 6 ]
then
alphabet="02 03 04 05 06"
count=0
fi
if [ $NUMBER -eq 7 ]
then
alphabet="02 03 04 05 06 07"
count=0
fi
if [ $NUMBER -eq 8 ]
then
alphabet="02 03 04 05 06 07 08"
count=0
fi
for letter in $alphabet
do
count=`expr $count + 1`
echo "$letter"
done > count.txt
Thanks for the reply. It definitely takes up less space, but I am still limited to a count of 8. I could add more lines, but I don't want to be limited by the number of lines I have in the file.
Last edited by LinuxRacr; 02-26-2008 at 04:09 AM..
Count will 'default' to zero, you do not set it for the first condition. But, you feel you must set within each case possibility? Why?
Couldn't you set it just once outside of the case statement?
Also, is your pupose here to simply create the count.txt file? There are easier ways to accomplish that.
I suppose you are correct. I put the counts back because of a syntax error I was getting. Let me try the script by taking out all counts, and putting it outside the "tree".
A 'continue' is normally only used (and needed) while inside some kind of loop - causing the execution to skip the rest of the processing and continue with the next iteration. Thus, your 'continue' may be not needed.
What is you final desired result? That count.txt file?
I put the counts back because of a syntax error I was getting.
What error?? don't forget you need the keep the ;; in each of the selections for a case statement.
If you really want to be unlimited, why use if or case?
You could set a variable, say MAX_CNT to the input supplied to your script,
set alphabet=2, and create a "while loop <less than or equal to MAX_CNT" add one more to alphabet. This way there's no limit at all to your script.
Hello all,
I need help making a script run faster since I have a huge file to sift through. The file I am running my script on looks like this:
1 -1.9E+001 -1.8E-001 1.5E+001 3.32E+001
2 -1.7E+001 -1.0E-002 1.2E+001 6.37E+001
3 -1.5E+001 -3.8E-006 6.7E+001 4.81E+001
The... (12 Replies)
hi
i am writing a korn shell script to compile all programs there are arount 2000+ files now i have a script that can compile programs but i want to show status of compilation because to compile all programs it takes around 10-15 mins so how can i display status like it should print no of files... (3 Replies)