I did make a post about my script to generate numbers combination depends on user input to set the number of digits a few weeks ago. And I was thinking to make it more clean and user friendly after received a comments from "Pak Leman".
So here is the update of the scripts. The script will asked user to input the digits of combination to generate. And will asked user to give the output filename. So no more "sh script 8 > huhu.txt" . To run the script just run "sh script" and it will ask you all the details using script.
So here is the full codes of the script, and also pictures of the output:
#!/bin/sh
echo "Please give the digits for combinations[8-63]: \c"
read digit
echo "Please type the output file name: \c"
read OUTFILE
FINISH=`expr "10^"$digit"" | bc -l`
if [ $digit -lt 8 -o $digit -gt 64 ]
then
clear
echo "The digit you specify is ' $digit '. "
echo "Please enter a valid digit [8-63]: \c"
read digit
else
break
fi
COUNT="-1"
while [ $COUNT != `expr $FINISH - 1` ] ; do
COUNT=`expr $COUNT + 1`
printf "%+"$digit"s\n" $COUNT | sed s^\ ^0^g >> $OUTFILE
done
So any opinion on how to improve the script are most welcome. Somehow the script still allow digits more than 63. Still looking forward to repair this script. Any thought or advise are welcome. Please drop some comments.
Thank you for your unbelievable support on Negative Zero - Permission to read and write blog for nearly 4 years. Don't forget to like Negative Zero on Facebook.
done >> $OUTFILE
ReplyDeleteyup.. done..
ReplyDeletedone >> $OUTFILE
owh... dah terel scripting rupanya... ;D
ReplyDeletejgn la mcm tu apogee..
ReplyDeleteanda masih lagi coder yang disegani..
:)
saya baru nk jenguk2 saja