I have the following script:
$ cat mathtest.m
pardir=DirectoryName @ $InputFileName;
Print["test parent dir: ", pardir]
If I run it like this, I get:
$ wolfram -script mathtest.m
test parent dir: /home/me/
If I run it like this, I get:
$ wolframscript -file mathtest.m
test parent dir:
Could somebody explain me this weird behavior? Apart from this I haven't noted any differences between running scripts in both methods. However, I do need the second one to give me the correct path.
I am on Wolfram Language 11.1.1 Engine for Linux x86 (64-bit).
Print["test parent dir: ", {$InputFileName, NotebookFileName[]}]? – Kuba Aug 23 '17 at 11:58NotebookFileName[]should only work with a front end, no ... ? Here it's command line only. The behaviour is weird indeed, and I don't like it, but there is a technical explanation for it (in the 'duplicate' answer I linked) – Szabolcs Aug 23 '17 at 12:09-fileto-scriptcalls. @Kuba, yes I also triedNotebookFileName[]and indeed I get the errorFrontEndObject::notavail. – Santiago Aug 23 '17 at 12:18$ScriptCommandLineinstead. – Szabolcs Aug 23 '17 at 12:24