Is there a way to read in command line arguments into a Gretl script?

193 Views Asked by At

I want to be able to pass in arguments to a Gretl script from the command line/bash script.

Alternatively, if I open Gretl from a bash script, is there a way to then output commands from the bash script to the gretl console in the terminal window?

3

There are 3 best solutions below

0
On BEST ANSWER

Turns out this is not possible. Ended up having to print to, and read from a text file in order to pass multiple arguments.

My recommendation is to never ever use Gretls command line function. It has quite a nice GUI to mess around, but if you want to use such a library as part of an application, use R.

0
On

You may pass arguments via (bash) environment variables. From inside gretl they may be recovered by means of the getenv() command.

0
On

It's perfectly possible via environment variables; I use this trick all the time when running large jobs.

Suppose you have a script like the following, inside the file f.inp

string foo = getenv("A")
scalar bar = ngetenv("N")
printf "%g kilograms of %s\n", bar, foo

In bash, you could simply go A="bread" N=3 gretlcli -b -q f.inp and get

? string foo = getenv("A")
Generated string foo
? scalar bar = ngetenv("N")
Generated scalar bar = 3
3 kilograms of bread