Hi all,
I'm going nuts with this...let me explain...
I have a very simple Bash script with a function in it that receives 3 arguments. Those arguments are all strings. Everything was working fine 'til I had to pass a string with whitespaces to the function.
I also have some test code to call the function (whose name is substracFromFile):
# try the function
PATTERN=`echo -e '<Location test14>'`
echo "PATTERN IS $PATTERN"
HEADERPATTERN=`echo -e '<Location [a-zA-Z0-9]*>'`
echo "HEADERPATTERN IS $HEADERPATTERN"
FILE="subversion.conf"
echo "FILE IS $FICHERO"
substracFromFile $PATTERN $HEADERPATTERN $FILE
The output of this is:
PATTERN IS <Location prueba14>
HEADERPATTERN IS <Location [a-zA-Z0-9]*>
FILE IS subversion.conf
PATTERN ARGUMENT IS <Location
HEADERPATTERN ARGUMENT IS prueba14>
FILE ARGUMENT IS <Location
grep: <Location: No such file or directory
expr: syntax error
As you can see, when arguments are passed to the function and I echoed them to screen they are somehow splitted in the white space...let me show you the function initial code:
function substracFromFile
{
PATTERN=$1
HEADERPATTERN=$2
FILE=$3
# Debug only
echo "HEADER ARGUMENT IS $PATTERN"
# Debug only
echo "HEADERPATTERN ARGUMENT IS $HEADERPATTERN"
# Debug only
echo "FILE ARGUMENT IS $FILE"
This was working sweet as long as passed strings had no whitespaces at all. When I call the function strings seem to be ok, but I don't understand why they are splitted once the function is called....I'm sure this is something pretty dull, but I just don't get it...
Thanks in advance, Alex