Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading arguments from console

I've written a console script, with a simple implementation of the Fibonacci recursive algorithm.

However, I searched in the docs and still cannot find how to get a number param from the command line. How is that possible?

Code:

#!/usr/local/bin/lgm -l

import core.number;

fibo(x) =>
{
    x<=1 :==> 1;
    ==> fibo(x-1)+fibo(x-2);
}
like image 985
Derek Almond Avatar asked Jan 10 '23 19:01

Derek Almond


2 Answers

Command line arguments are stored in the __Args variable.

So, you can use them pretty much like any normal array.

like image 181
G.Stevens Avatar answered Jan 18 '23 12:01

G.Stevens


@G.Stevens is correct.

Commands line arguments can be accessed via the global __Args variable.

So, in your case, if you need the first argument, all you have to do is __Args[0].

And since you want is as number :

__Args[0].fromBase(10)

from core.number (which you're already importing anyway...)

like image 41
Dr.Kameleon Avatar answered Jan 18 '23 11:01

Dr.Kameleon