Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • that's a really good answer! just a note in case you're unaware: the function keyword when used with () for a function definition serves no purpose except to make your script less portable. the function keyword automatically automatically ignores the definition anyway and it winds up parsed as if the function keyword were not used at all. but your script is really good - and i think its awesome you came back to answer your own question. 9 times out of 10, these are the best answers. Commented Nov 27, 2015 at 10:26
  • @mikeserv I already removed the brackets according to your explanation. Thank you for your help and comments along this lttle script! Commented Nov 27, 2015 at 13:19
  • i don't know if you fully understood me: what i was suggesting was just that you do main(){ ...; } rather than function main(){ ...; } because the latter form doesn't work in as many host shells as the former, and the latter doesn't offer any advantage over the former in those in which it does. the other way to do it is function main { ...; } but that is only useful if you want to localize traps and variables per function. the variables can be fairly portably localized with the local builtin declaration command, anyway, by the way. Commented Nov 27, 2015 at 13:26
  • Good thing you clarified it for me. I really did missunderstand. After a bit of reading I agree with you, it's not that portable. Another thing for me to remember! Commented Nov 28, 2015 at 11:54