shell script error if "read -a" is used
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
if [[ ! $file_name_package ]]; then
fi
if [[ $package_check == $1 ]]; then
fi
fi
done
exec 0<&3
}
The file the script tries to read looks like this:
FILE:
## Main
cms Main.GroupConfig /pub/netstreams
WORKING BASH:
bash, version 3.2.25(
Bash wos nicht funktioniert ubuntu 8.04:
UBUNTU BASH:
bash, version 3.2.39(
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.