【问题标题】:syntax error when taking a code from mac to linux machine将代码从 mac 转移到 linux 机器时出现语法错误
【发布时间】:2019-11-16 16:22:40
【问题描述】:

我编写了这段代码,用于在我的 Linux 远程机器上执行一些不同输入的重复实验。

#!/bin/bash
#timeout 10m
trap "exit 1" INT 

repeat() {
  executiontime=$( /usr/bin/time  /home/me/optimathsat-1.5.1-macos-64-bit/bin/optimathsat < file.smt2 2>&1 >/dev/null)
  echo "$executiontime">>results.csv

}
export -f repeat

for length in 30 ; do
    step=0.05
    short=0 #0
    long=1
    for i in {1..10}; do
    ratio=0
        for j in {1..10}; do
                declare -a listofresults
                echo "$length $short $long $ratio">>results.csv
                python3 main.py "$length" "$short" "$long" "$ratio">file.smt2
                chmod 775 file.smt2
                declare total=0
                declare m=0
                parallel -n0 repeat ::: {1..10}
                ratio=$(echo "scale=10; ($ratio) + ($step)" | bc) 
            done
            short=$(echo "scale=10; ($short) + ($step)" | bc)
            long=$(echo "scale=10; ($long) - ($step)" | bc)
        done
    done
trap - INT

我已经在我自己的 mac 机器上执行了这段代码并且它可以工作(使用 gtime 而不是 /usr/bin/time )但是现在我收到了这个错误,我不知道它是什么意思/

   0inputs+0outputs (0major+66minor)pagefaults 0swaps
    /home/me/optimathsat-1.5.1-macos-64-bit/bin/optimathsat: 1: /home/project/optimathsat-1.5.1-macos-64-bit/bin/optimathsat:

 Syntax error: word unexpected (expecting ")")

当我尝试手动执行指令时,我得到了这个:

src$ python3 main.py 10 0.5 0.5 0.5>file.smt2

我检查了file.smt2,它应该是,然后发生这种情况

src$ /home/project/optimathsat-1.5.1-macos-64-bit/bin/optimathsat < file.smt2
    -bash: /home/project/optimathsat-1.5.1-macos-64-bit/bin/optimathsat: cannot execute binary file: Exec format error

【问题讨论】:

  • 为什么用python标记?
  • 错字:!/bin/bash 应该是#!/bin/bash
  • 能否请您运行带有跟踪的脚本?那是$ bash -x myscript.sh。它将显示导致错误的行。见tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
  • @waffles123,请确保向我们显示准确的minimal reproducible example。我们不能指望猜测哪些错误是相关的,哪些不相关。复制和粘贴是最好的。
  • 我认为问题出在optimathsat 程序中,而不是这个脚本中。

标签: linux bash macos shell optimathsat


【解决方案1】:
  • 您可以从使用跟踪$ bash -x myscript.sh 进行调试开始。它将显示导致错误的行。见The Linux Documentation Project's guide
  • 我总是觉得 macOS 不区分大小写,尽管它保留了大小写。也就是说,我可以在 macOS 上echo "Hello" &gt; foo; cat Foo,但在 Linux 上不行。
  • macOS 是基于 BSD,而不是基于 Linux。有一些基本命令在两个系统之间具有不同的标志。

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 2013-07-25
    • 2014-05-25
    • 1970-01-01
    • 2019-02-13
    相关资源
    最近更新 更多