contents   index   previous   next

main() function


If a script has a function called main(), it is the first function executed. (For more information on what takes place when a script is run, see the section on running a script.) Other than the fact that main() is the first function executed, it is like other functions. If the main() function returns a value, that value is returned to the operating system or whatever process called the script.


The main() function automatically receives two parameters, which, by convention, are called argc and argv. The parameter argc, argument count, is the number of parameters passed to the script and the parameter argv is an array of strings, with each element being one of the parameters. The first element, argv[0], of this array is always the name of the script, thus if argc == 1, then no variables were passed to a script.


Arguments are passed to a script as parameters when it is called from a command line as illustrated in the following line.


sewin32.exe jseedit.jse document.txt


In the example above, argc == 2, argv[0] == "jseedit.jse" and argv[1] == "document.txt".