Bash: Problem to run a function in Case
#!/bin/bash
getMatches (){
str=( $2 )
pattern=$3
sizePat=${#pattern}
let x=$sizePat-1
for (( i=0 ; i<${#str[*]} ; i=i+1 ))
do
for (( j=0 ; j<${#str[${i}][*]} ; j=j+1 ))
do
if [ ${str[${i}]:${j}:${j+$sizePat}} = $pattern ];
then let x=x+1
var[${i}]=${str[${i}]}
let i=i+1
let j=-1
let x=$sizePat-1
fi
done
done
echo "var "${var[*]}
}
cmd=$1
case $cmd in
-r)
getMatches $1 $2 $3;;
*)
getMatches x 'asd qwe asd1 asd2' as
esac
if I run:
./script.sh -r 'asd qwe asd1 asd2' as
the variable var is empty,
but if I run:
./script.sh
the resul is:
var asd asd1 asd2
how can I give the arguments throw the console? anyone can help me?
thx
I HAVE SOLVED THE PROBLEM ALREADY... thx... i was declaring the variables inside the function :/
Last edited by mitramcc; 02-11-2009 at 08:39 AM.
|