arguments to scripts...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

arguments to scripts...

Stefano Ghirlanda
Hi,
pardon me for the possibly trivial question:
how do you pass arguments to a script file?
Is there something like the $1, $2 etc. shell parameters?

thanks for octave, which I found every day more useful.

Stefano Ghirlanda, Zoologiska Institutionen, Stockholms Universitet
Office: Frescati Campus, Hus D, Rum 554. Office Phone: +46-8-164055
Mail: Svante Arrheniusv. 14, S-106 91, Stockholm, Sweden          
E-mail: [hidden email], Web: http://rerumnatura.zool.su.se


Reply | Threaded
Open this post in threaded view
|

arguments to scripts...

John W. Eaton-6
On 27-Mar-1998, Stefano Ghirlanda <[hidden email]> wrote:

| pardon me for the possibly trivial question:
| how do you pass arguments to a script file?
| Is there something like the $1, $2 etc. shell parameters?

You don't say which version of Octave you are using, or exactly how
you want to call your script.

With the current release, if you make an executable program out of
your script using the `#! /path/to/octave' hack available on most Unix
systems, you can do something like this

  #! /path/to/octave -qf
  printf ("%s", program_name);
  for i = 1:nargin
    printf (" %s", argv(i,:));
  endfor
  printf ("\n");

and

  ./program-name foo bar etc

will reproduce the command line on the standard output.

If you want to call your script from the Octave command line, you can
either use variables in the workspace (variables in script files are
share the same scope with the calling procedure) or you can convert
your script to a function and pass arguments to it in the normal way
for calling functions.

jwe


Reply | Threaded
Open this post in threaded view
|

Re: arguments to scripts...

wkim+
In reply to this post by Stefano Ghirlanda
> Date: Fri, 27 Mar 98 11:39:50 -0600
> From: "John W. Eaton" <[hidden email]>
> Subject: arguments to scripts...
>
> With the current release, if you make an executable program out of
> your script using the `#! /path/to/octave' hack available on most Unix
> systems, you can do something like this
>
>   #! /path/to/octave -qf
>   printf ("%s", program_name);
>   for i = 1:nargin
>     printf (" %s", argv(i,:));
>   endfor
>   printf ("\n");
>
> and
>
>   ./program-name foo bar etc
>
> will reproduce the command line on the standard output.
>
> If you want to call your script from the Octave command line, you can
> either use variables in the workspace (variables in script files are
> share the same scope with the calling procedure) or you can convert
> your script to a function and pass arguments to it in the normal way
> for calling functions.
>
> jwe

It's good to know that this also works with OS/2 .cmd script.
(replace the 1st line to:  extproc octave -qf).

Thank you.

//--------------------------------------------------------------------
// Wonkoo Kim ([hidden email])