Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic bash script returns "invalid syntax"

Tags:

bash

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.
like image 462
Sam Odio Avatar asked Apr 24 '15 23:04

Sam Odio


People also ask

How do I fix SyntaxError invalid syntax?

The message reads SyntaxError: invalid syntax , but that's not very helpful. The traceback points to the first place where Python could detect that something was wrong. To fix this sort of error, make sure that all of your Python keywords are spelled correctly.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

What is $? == 0 in shell script?

$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.

What's do `` $() ${} commands do in bash?

$() – the command substitution. ${} – the parameter substitution/variable expansion.


1 Answers

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.

It's a bash script, so just use bash to process it:

./test.sh
like image 92
scrowler Avatar answered Sep 21 '22 23:09

scrowler