Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top