Hi,
I have a strange problem. I need to change a command to a function.
Theoretically that works like a charm. But now I want to make that
definition a bit more general and struggle as variables gets not
evaluated when it should be.
Here is my definition:
```
for i in pdfgrep rg
do
if whence -p "$i" >&-
then
"$i"()
{
local -a arg
local val
for val in "$@"
do
if [[ -a "$val" ]]
then
arg+="$val"
else
arg+="$(print -- "$val" | iconv -f $(locale charmap) -t UTF-8)"
fi
done
command "$i" "$arg[@]"
}
fi
done
```
When I do that, I get the following for pdfgrep:
```
~> which pdfgrep
pdfgrep () {
local -a arg
local val
for val in "$@"
do
if [[ -a "$val" ]]
then
arg+="$val"
else
arg+="$(print -- "$val" | iconv -f $(locale charmap) -t UTF-8)"
fi
done
command "$i" "$arg[@]"
}
```
As you can see, $i is not evaluated in the function definition.
Is there any way to evaluate $i inside the function definition; but only
that variable?
Regards
Klaus
--
Klaus Ethgen http://www.ethgen.ch/
pub 4096R/4E20AF1C 2011-05-16 Klaus Ethgen <Klaus@xxxxxxxxx>
Fingerprint: 85D4 CA42 952C 949B 1753 62B3 79D0 B06F 4E20 AF1C
Attachment:
signature.asc
Description: PGP signature