Bash scripts using arrays fail

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
ioctlvoid

Bash scripts using arrays fail

Post by ioctlvoid »

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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
eanfrid

Re: Bash scripts using arrays fail

Post by eanfrid »

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

Re: Bash scripts using arrays fail

Post by ioctlvoid »

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?
eanfrid

Re: Bash scripts using arrays fail

Post by eanfrid »

You can safely use any alternative you like. Regarding dash, check wikipedia: https://en.wikipedia.org/wiki/Debian_Almquist_shell
ioctlvoid

Re: Bash scripts using arrays fail

Post by ioctlvoid »

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?
eanfrid

Re: Bash scripts using arrays fail

Post by eanfrid »

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.
Locked

Return to “Software & Applications”