I have made a simple script to find all programs that use a tcp wrapper, it will supply a reasonable default for my system if none is given.
After some digging I realized that the expansion operators pass their default return value single quoted (according to bash -x trace). I have wildcard expansions in my return value, and it works if used with eval.
Its working perfect with eval, but I don't know why.
#! /bin/bash
ldd_path="$*"
while read line
do
if [[ "$line" =~ ^/.*:$ ]]
then
current_binary="$line"
elif [[ "$line" =~ .*libwrap.so.0.* ]]
then
printf '%s\n' "$current_binary"
fi
done < <(eval ldd ${ldd_path:-"/usr/bin/* /usr/sbin/*"})
My question is really how is eval working with wildcards if they are passed with single quotes, bash -x shows eval working on this:
eval ldd '/usr/bin/* /usr/sbin/*'
I though evaluation order will prevent this from working but it is.
Can somebody elaborate on this for me