# Script with command line argument

As a test I want a simple script to take a command line argument and print it to a file:

Export["c://cygwin/home/jorgen/yu.dat",$ScriptCommandLine[[2]],"Data"] // MatrixForm; However when I run this with ./MathKernel -script Swargtest.m 45 the resulting file yu.dat looks like this: {}[[2]] I've tried what I could think of: making another variable with out=$ScriptCommandLine[[2]] and exporting that, removing the $, running the script with '45' and "45" on the command line, etc. I'm using cygwin on a windows 7 machine. - I see no extra argument (such as your 45) allowed AFTER the file name mentioned here: reference.wolfram.com/mathematica/ref/program/MathKernel.html , Where did you see such a possible argument at that position? It says: -script "file" execute the commands from the in a script mode – Nasser Sep 2 '13 at 12:59 From the docs: "If the Mathematica kernel was run in a way other than via a MathematicaScript mechanism, the$ScriptCommandLine gives an empty list." –  Pickett Sep 2 '13 at 13:05
Oh I see now, I have to use \$CommandLine. My bad! What's the custom here, should I delete this question? –  jorgen Sep 2 '13 at 13:09
@jorgen: I think it would be best if you provide an answer and accept it. It is common and welcomed to answer one's own questions and also to accept it. You might want to refer to Anons comment in this case... –  Albert Retey Sep 3 '13 at 9:58