【问题标题】:Failed to execute bash script on mac无法在 mac 上执行 bash 脚本
【发布时间】:2018-10-31 03:19:30
【问题描述】:

我创建了以下简单的测试脚本

#!/bin/bash

echo "test"

我使用chmod +x ./msa.sh来执行它。

现在,当我尝试运行它时 喜欢./msa 我收到以下错误,

Failed to execute process ‘./msa.sh'. Reason:
exec: Exec format error
The file './msa.sh' is marked as an executable but could not be run by the operating system.

我正在使用macfish,我应该怎么做才能成功运行它?

【问题讨论】:

    标签: bash macos shell sh fish


    【解决方案1】:

    您确定将脚本保存为纯文本文件吗?如果您使用的是 TextEdit,您可能会保存一个 RTF。如果需要,请选择“格式”>“制作纯文本”并重新保存文件。

    您还可以从 shell 检查文件以确保它以您期望的 shebang 行开头。例如:

    nicholas@mary ~> file msa.sh
    msa.sh: Rich Text Format data, version 1, ANSI
    nicholas@mary ~> head -1 msa.sh
    {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf400
    

    不是你想要的。

    nicholas@mary ~> file msa.sh
    msa.sh: Bourne-Again shell script, ASCII text executable
    nicholas@mary ~> head -1 msa.sh
    #!/bin/bash
    

    这就是你想要的。

    【讨论】:

      猜你喜欢
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      相关资源
      最近更新 更多