编写一个测试 shell 的脚本

编写一个测试 shell 的脚本

我有一个自定义 shell,想测试它的算术功能。我编写了一个脚本来测试它,它执行算术,但它也试图将结果作为程序执行。

  printf "********************* TEST Arithmetics  ... .\nYou should see the number 4096 below "
    #read _
    valgrind --leak-check=yes ./shell .<< EOF
    $((64 * 64))
    EOF

结果: failed to execute 4096: (2: No such file or directory)

= 正确答案与错误相连。

如果我运行测试,表达式$((64 * 64))将会求值,但我也会收到一条错误消息。奇怪的是,如果我从 JetBrain Clion 内部运行项目,我只会收到此错误消息,如果我在终端模式下运行 shell 而不是针对它进行自动化测试,我不会在终端中收到此错误消息。

$ $((64 * 64))
Result = 4096
$ 

您认为错误是在测试中还是在 shell 中?

答案1

$(( 64*64 ))会直接在命令行中输入 4096,然后说,继续运行它。因此出现错误

 failed to execute 4096: (2: No such file or directory)

如果您只想执行计算而不打印,请删除 $。如果您确实想打印,请使用echo $(( 64*64))

相关内容