无法在 mac 上执行 bash 脚本
Failed to execute bash script on mac
我创建了以下简单的测试脚本
#!/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.
我正在使用 mac
和 fish
,我应该怎么做才能成功 运行?
您确定要将脚本保存为纯文本文件吗?如果您使用的是 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
这就是你想要的。
我创建了以下简单的测试脚本
#!/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.
我正在使用 mac
和 fish
,我应该怎么做才能成功 运行?
您确定要将脚本保存为纯文本文件吗?如果您使用的是 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
这就是你想要的。