in reply to need help on shell scripting

In my humble, with the sole exception of the Korn shell, a shell is not really intended for programming, and is really not suited for it, although undeniably this is routinely done.   You can hammer a nail with a piece of iron pipe, too, or remove a nail with a wrench, but it’s a profitless use of your imagination and ingenuity.

“That’s what ‘shebang’ (#!) is for.”   You can write programs in any one of a dozen suitable scripting/programming languages, of which Perl, of course, is the best.   ;-)   No one who merely runs the script will know, or care in the slightest, how it’s done.