Bash script with regex not behaving on Ubuntu
Posted
by
user265330
on Stack Overflow
See other posts from Stack Overflow
or by user265330
Published on 2012-07-03T14:56:44Z
Indexed on
2012/07/03
15:15 UTC
Read the original article
Hit count: 208
I have a Bash script that is working on my OpenSuSE box, but when copied across to my Ubuntu box, is not working. The script reads in from a file. The file has fields separated by white space (tabs and spaces).
#!/bin/bash
function test1()
{
while read LINE
do
if [[ $LINE =~ "^$" || $LINE =~ "^#.*" ]] ; then
continue;
fi
set -- $LINE
local field1=$1
local field2=$2
done < test.file
}
test1
with test.file containing:
# Field1Header Field2Header
abcdef A-2
ghijkl B-3
There seem to be two problems:
(1) $field2, the one with the hyphen, is blank
(2) The regex to strip out the blank lines and lines that start with # is not working
Anyone know what's wrong? As I said, it works fine on OpenSuSE.
Thanks, Paul
© Stack Overflow or respective owner