shell script error if "read -a" is used

Bug #474638 reported by ben
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: dash

hi
I noticed a problem when migrating my server from centos to ubuntu 9.1. The scripts don't work anymore. I checked them on debian and other system, where they worked fine. However I'm not a pro in script writing, but still seams strange that they don't work anymore. So I would realy be happy if the problem could be solved somehow.

If I run the script I get the error:

ERROR:
    read: 160: Illegal option -a

CODE:
AbgleichProzess()
{
exec 3<&0
exec 0<$FILE

while read -a a line; do
if [[ ! ${a[0]} = \#* && ${a[0]} ]]; then
        package_check=${a[0]}
        file_name_installation=${a[1]}
        file_location_package=${a[2]}
        file_name_package=${a[3]}

        if [[ ! $file_name_package ]]; then
                file_name_package=$file_name_installation
        fi

        if [[ $package_check == $1 ]]; then
                DateiAbgleich $path_packages $path_installation $1 $file_name_package $file_name_installation $file_location_package
        fi

fi
done

exec 0<&3
}

The file the script tries to read looks like this:

FILE:
## Main
cms Main.GroupConfig /pub/netstreams/wikilib.d/

WORKING BASH:
bash, version 3.2.25(1)-release-(i686-redhat-linux-gnu)
Bash wos nicht funktioniert ubuntu 8.04:

UBUNTU BASH:
bash, version 3.2.39(1)-release-(x86_64-pc-linux-gnu)

Tags: bash
Revision history for this message
Jilles Tjoelker (jilles) wrote :

Dash deliberately does not support arrays, so this is not a bug in dash.

I suggest changing the #!/bin/sh line at the start of the script to #!/bin/bash. (Note that bash enters posix mode when it is called as 'sh', so it may be a good idea to add (set -o posix) 2>/dev/null && set -o posix to the beginning of the script as well.)

If you want to use dash, you have to change the read command to something like read package_check file_name_installation file_location_package file_name_package. You also have to change all the [[ conditional commands ]] to [ builtins ], taking note that [ ] has somewhat different syntax.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.