Bash scripts using arrays fail

Questions about applications and software
Forum rules
Before you post please read this

Bash scripts using arrays fail

Postby ioctlvoid on Tue Jan 29, 2013 5:29 pm

I have several bash scripts that I've used successfully in Slackware that fail in Mint. The ones that fail all use arrays in some way. I thought perhaps I was using arrays in the wrong way, but even examples from e.g. http://www.thegeekstuff.com/2010/06/bas ... -tutorial/ fail.

E.g.

Code: Select all
#!/bin/sh

declare -a Unix=('Debian' 'Red hat' 'Red hat' 'Suse' 'Fedora');
echo ${Unix[@]}


Fail with:

Code: Select all
./array.sh: 3: ./array.sh: Syntax error: "(" unexpected


Why does this happen?
ioctlvoid
Level 1
Level 1
 
Posts: 28
Joined: Tue Jan 08, 2013 9:23 am

Linux Mint is funded by ads and donations.
 

Re: Bash scripts using arrays fail

Postby eanfrid on Tue Jan 29, 2013 5:54 pm

Your default shell called by the symlink /bin/sh is not bash but dash (debian shell), hence the error message :)
No, Linux is not a Windows clone for free - Before asking any question here...
"Never attribute to malice that which is adequately explained by stupidity." (Hanlon's razor)

Debian GNU/Linux Wheezy 64bit w/custom 3.12 kernel - MATE 1.8
User avatar
eanfrid
Level 6
Level 6
 
Posts: 1211
Joined: Mon Apr 30, 2012 2:49 am
Location: France

Re: Bash scripts using arrays fail

Postby ioctlvoid on Tue Jan 29, 2013 6:03 pm

eanfrid wrote:Your default shell called by the symlink /bin/sh is not bash but dash (debian shell), hence the error message :)


Thanks. Is that symlink safe to change to bash? Why does it by default point to dash?
ioctlvoid
Level 1
Level 1
 
Posts: 28
Joined: Tue Jan 08, 2013 9:23 am

Re: Bash scripts using arrays fail

Postby eanfrid on Tue Jan 29, 2013 6:07 pm

You can safely use any alternative you like. Regarding dash, check wikipedia: https://en.wikipedia.org/wiki/Debian_Almquist_shell
No, Linux is not a Windows clone for free - Before asking any question here...
"Never attribute to malice that which is adequately explained by stupidity." (Hanlon's razor)

Debian GNU/Linux Wheezy 64bit w/custom 3.12 kernel - MATE 1.8
User avatar
eanfrid
Level 6
Level 6
 
Posts: 1211
Joined: Mon Apr 30, 2012 2:49 am
Location: France

Re: Bash scripts using arrays fail

Postby ioctlvoid on Tue Jan 29, 2013 6:51 pm

eanfrid wrote:You can safely use any alternative you like.


Thanks.

eanfrid wrote:Regarding dash, check wikipedia: https://en.wikipedia.org/wiki/Debian_Almquist_shell


So Mint throws away essential scripting functionality in the name of saving 800 kB?
ioctlvoid
Level 1
Level 1
 
Posts: 28
Joined: Tue Jan 08, 2013 9:23 am

Re: Bash scripts using arrays fail

Postby eanfrid on Tue Jan 29, 2013 7:23 pm

Mint's primary target is not the technical user (who can do and change whatever suits his (her) needs). Common users won't make complex scripting (if any) and even then, there are many non-shell alternatives or programming languages... I used bash for many years too but I finally think its extended functions are rather in the realm of a true programming language than in the realm of command-line interpreters.
No, Linux is not a Windows clone for free - Before asking any question here...
"Never attribute to malice that which is adequately explained by stupidity." (Hanlon's razor)

Debian GNU/Linux Wheezy 64bit w/custom 3.12 kernel - MATE 1.8
User avatar
eanfrid
Level 6
Level 6
 
Posts: 1211
Joined: Mon Apr 30, 2012 2:49 am
Location: France


Return to Software & Applications

Who is online

Users browsing this forum: peterldg and 14 guests