我创建了以下简单的测试脚本
#!/bin/bash
echo "test"
Run Code Online (Sandbox Code Playgroud)
我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.
Run Code Online (Sandbox Code Playgroud)
我使用的是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
Run Code Online (Sandbox Code Playgroud)
那不是你想要的.
nicholas@mary ~> file msa.sh
msa.sh: Bourne-Again shell script, ASCII text executable
nicholas@mary ~> head -1 msa.sh
#!/bin/bash
Run Code Online (Sandbox Code Playgroud)
这就是你想要的.