Why would I want to use main() in an ash script rather than just list the lines of code to be executed? I know that declaring main with parameters will trigger a dialog with the user to get values for those parameters, but are there any other reasons or advantages to use main()? Note this is more of a why? question than it is a how? question.
Perhaps related, encapsulation. I am tweaking code from zarqon that has a function that uses a map. The map functions as both a cache and a repository so it needs to be read from a file before the function is used and written to a file. The function could be self contained by reading and writing the map from within the function, but doing so seems somewhat inefficient in terms of disk I/O. How do (or can) I organize things so that things are stand alone and so perhaps could be reused elsewhere? The best analogy might be from an object lifecycle whereby there is a place for things to be called when then object is created and another place for where it can release resources and clean up before it is destroyed.
Thanks.
Perhaps related, encapsulation. I am tweaking code from zarqon that has a function that uses a map. The map functions as both a cache and a repository so it needs to be read from a file before the function is used and written to a file. The function could be self contained by reading and writing the map from within the function, but doing so seems somewhat inefficient in terms of disk I/O. How do (or can) I organize things so that things are stand alone and so perhaps could be reused elsewhere? The best analogy might be from an object lifecycle whereby there is a place for things to be called when then object is created and another place for where it can release resources and clean up before it is destroyed.
Thanks.