kpsewhich -expand-var=$TEXMFDIST Not relevant to Lua, but for the record, the potential problems with $ are exactly why the -var-value option exists (I put it in at Hans' request, as I recall): kpsewhich -var-value=TEXMFDIST (or without the =).