基本 bash 脚本返回“无效语法”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29858945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Basic bash script returns "invalid syntax"
提问by Sam Odio
Can't explain why this is happening. Here's the script:
无法解释为什么会发生这种情况。这是脚本:
#!/bin/bash
echo "Hello World"
Here's the terminal output:
这是终端输出:
$ 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.
回答by Robbie Averill
Looks like you're parsing it with python, since it's not a python script - it of course will throw errors in python's compiler.
看起来你正在用 python 解析它,因为它不是一个 python 脚本——它当然会在 python 的编译器中抛出错误。
It's a bash script, so just use bash to process it:
这是一个 bash 脚本,所以只需使用 bash 来处理它:
./test.sh