[racket] want to pass argument via terminal in linux

From: Danny Yoo (dyoo at hashcollision.org)
Date: Wed Mar 20 00:25:18 EDT 2013

> I need to pass a file name as a parameter to my program (e.g. test-
> case1.rkt). in that file I just have a list variable.
>
> I want to do it via terminal in this way:
> ---------------------------------------------------------------
> racket ./Desktop/a3/1/a3-FC.rkt ./Desktop/a3/1/test-case1.rkt
> ---------------------------------------------------------------
> what should I do in the a3-FC.rkt file?

For simple stuff, you can look at the 'current-command-line-arguments'
parameter, which is a vector of the passed arguments.

    http://docs.racket-lang.org/reference/runtime.html#%28def._%28%28quote._~23~25kernel%29._current-command-line-arguments%29%29

For example:

;;;;;;;;;;;;;;;;;;;;;
#lang racket
(printf "The current command line arguments I see are: ~s"
(current-command-line-arguments))
;;;;;;;;;;;;;;;;;;;;;

should show that you get back the arguments as a vector of strings.


If you want to do something more sophisticated in terms of command
line argument processing, you may want to look at the racket/cmdline
library:

    http://docs.racket-lang.org/reference/Command-Line_Parsing.html

where it handles things like handling switches and optional
parameters.  It also generates a "--help" command for you.


I hope this helps!

Posted on the users mailing list.