Heres an example script, temp.sl:
==============
#!/usr/bin/env slsh
define slsh_main ()
{
message (string (__argc));
return;
}
=============
When I try "slsh temp.sl", the result is "1".
When I try "slsh temp.sl 8", the result is "2".
The result is also "2" regardless of any number I try.
What am I doing wrong?
I also tried sprintf, but the results where the same.
__argc gives the number of command line arguments passed to the
script, with the name of the script counted as the first argument.
Try this:
define slsh_main ()
{
variable i;
for (i = 0; i < __argc; i++)
vmessage ("argv[%d] = %s", i, __argv[i]);
}
FWIW, here is a template that I use for my slsh scripts:
#!/usr/bin/env slsh
private variable Script_Version_String = "0.1.0";
require ("cmdopt");
private define exit_version ()
{
() = fprintf (stdout, "Version: %S\n", Script_Version_String);
exit (0);
}
private define exit_usage ()
{
variable fp = stderr;
() = fprintf (fp, "Usage: %s [options] REQUIRED-ARGS\n", __argv[0]);
variable opts =
[
"Options:\n",
" -v|--version Print version\n",
" -h|--help This message\n",
];
foreach (opts)
{
variable opt = ();
() = fputs (opt, fp);
}
exit (1);
}
define slsh_main ()
{
variable c = cmdopt_new ();
c.add("h|help", &exit_usage);
c.add("v|version", &exit_version);
variable i = c.process (__argv, 1);
% modify the next line to account for the number of required
% arguments
if (i != __argc)
exit_usage ();
% Rest of the code goes here.
}
Good luck,
--John
> __argc gives the number of command line arguments passed to the
> script, with the name of the script counted as the first argument.
Oh, I didn't realise that they were arrays. I just saw "__argc" in the
introductory documentation and that's what I tried.
Thanks.
You will find some documentation on command line processing by slsh
scripts at <http://www.jedsoft.org/slang/doc/html/slang.html#toc19.2>.
--John