Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k
added 178 characters in body
Source Link
IGGt
  • 2.6k
  • 9
  • 36
  • 48

I have two (Debian) Linux servers. I am creating a shell script.

On the first one I create an array thus:

#!/bin/bash
target_array=(
    "/home/user/direct/filename -p123 -r"
)

That works fine. But when I run this on the other server I get:

Syntax error: "(" unexpected

As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work?

If I type it into the terminal directly it is fine??


It would appear that when I run it as

sh scriptname.sh

I get the error, but if I run it as

./scriptname.sh

it seems to be ok. What's the difference?

I have two (Debian) Linux servers. I am creating a shell script.

On the first one I create an array thus:

#!/bin/bash
target_array=(
    "/home/user/direct/filename -p123 -r"
)

That works fine. But when I run this on the other server I get:

Syntax error: "(" unexpected

As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work?

If I type it into the terminal directly it is fine??

I have two (Debian) Linux servers. I am creating a shell script.

On the first one I create an array thus:

#!/bin/bash
target_array=(
    "/home/user/direct/filename -p123 -r"
)

That works fine. But when I run this on the other server I get:

Syntax error: "(" unexpected

As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work?

If I type it into the terminal directly it is fine??


It would appear that when I run it as

sh scriptname.sh

I get the error, but if I run it as

./scriptname.sh

it seems to be ok. What's the difference?

Source Link
IGGt
  • 2.6k
  • 9
  • 36
  • 48

`Syntax error: "(" unexpected` when creating an array

I have two (Debian) Linux servers. I am creating a shell script.

On the first one I create an array thus:

#!/bin/bash
target_array=(
    "/home/user/direct/filename -p123 -r"
)

That works fine. But when I run this on the other server I get:

Syntax error: "(" unexpected

As far as I can tell both servers are the same. Can anyone shed some light on why this doesn't work?

If I type it into the terminal directly it is fine??