0

I used to have a server running CentOS, and I used to execute shell files this way:

sudo sh /folder/script.sh

Now I have an Ubuntu server. When I'm executing the same command line, I now have the following error message:

/folder/script.sh: ID[0]=ID: not found 

I had a look on the internet and it says I need to use:

sudo /bin/bash /folder/script.sh

But when I do so I got the same error message.

The first line of my script is:

ID[0]="ID"
4
  • paste first few lines of your script. You might be missing shebang.. Commented Dec 22, 2014 at 10:47
  • thanks a lot for having a look @almasshaikh I just edited my message Commented Dec 22, 2014 at 10:55
  • add this #!/bin/bash as a first line. Commented Dec 22, 2014 at 10:57
  • still got the same error @almasshaikh Commented Dec 22, 2014 at 11:24

1 Answer 1

1

/bin/sh is often a POSIX shell, which does not support arrays.

I suggest you install another shell which does support them, like mksh (disclaimer: I’m its developer), ksh93, zsh, or just use GNU bash instead, and call your script with, for example, sudo mksh /folder/script.sh instead. This will give you more consistent behaviour across systems, too (note that to behave consistent on all platforms is actually an mksh design goal).

Hm… this works for me:

$ cat >x
#!/bin/bash
ID[0]="ID"
echo works for me
$ mksh x
works for me

Do you have any weird characters in your script, like embedded Carriage Return (^M)? Check with: cat -v /folder/script.sh

Sign up to request clarification or add additional context in comments.

3 Comments

i got exactly the same error : "ID[0]=ID: not found"
Thanks for your help, I used mksh, well actually "ID[0]=ID: not found" is the second line, the first line is #!/bin/bash
it also works for me, in your example you are not quotting your string, gotta try this way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.