基本bash脚本返回"无效语法"

Sam*_*dio 3 bash

无法解释为什么会这样.这是脚本:

#!/bin/bash
echo "Hello World"
Run Code Online (Sandbox Code Playgroud)

这是终端输出:

$ python ./test.sh 
    File "./tellapart_mac_setup.sh", line 2
        echo "Hello World"
        ^
SyntaxError: invalid syntax

$ echo "hello world"
hello world

$ which bash
/bin/bash

$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
Copyright (C) 2007 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)

Rob*_*ill 11

看起来你正在用python解析它,因为它不是python脚本 - 它当然会在python的编译器中抛出错误.

这是一个bash脚本,所以只需使用bash来处理它:

./test.sh
Run Code Online (Sandbox Code Playgroud)

  • 谁高谁来到这里? (5认同)