3
$\begingroup$

Here's a simple script saved in the file fortranOutput.wls

x = ToExpression[$ScriptCommandLine[[2]]]
d=FortranForm[x]
Print[d]

When I call this function from the terminal :

./fortranOuput.wls 1.2*^-8

I get the output (I am using Ubuntu 20.04.5 LTS):

FortranForm[1.2*^-8]

Obviously, the answer I expect (and receive in the Mathematica environment) is:

1.2e-8
$\endgroup$

1 Answer 1

3
$\begingroup$
x = ToExpression[$ScriptCommandLine[[2]]]
Print[x]
Echo[ToString@FortranForm[x]]

I am on Windows 7-x64 with v12.2.0:

> C:\MathematicaWork>ascript.wls "1.2*^-8"
> 1.2*^-8
> >> 1.2e-8
$\endgroup$
4
  • $\begingroup$ my machine is Ubuntu 20.04. It works but I am getting the extra characters ">>" $\endgroup$ Dec 13, 2022 at 17:21
  • 1
    $\begingroup$ Try Print instead of Echo ? $\endgroup$
    – Syed
    Dec 13, 2022 at 17:22
  • $\begingroup$ It works. Thanks a lot. $\endgroup$ Dec 13, 2022 at 17:29
  • $\begingroup$ You are welcome. You can accept the answer by clicking on the checkmark next to the answer. Thanks. $\endgroup$
    – Syed
    Dec 13, 2022 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.