I have the following script:
#!/bin/sh
[ "${#}" -eq "0" ] && (printf "%s\\n" "${0}: word ..." >&2; exit 1)
_whats()
{
[ -z "${1}" ] && return 1
[ -z "${2}" ] && more_than_one="1"
for word; do
response="$(dig +short txt ${word}.wp.dg.cx)"
printf "%s\\n" "${response}"
if [ -z "${more_than_one}" ]; then
printf "\\n%s\\n\\n" ":::::::::::::::::::::::::::::::::::::::::"
fi
done
}
_whats "${@}"
It works great when I call it this way:
whats shell\ script dns #it ouputs two definitions (shell script and dns)
However I'd also to call it this way:
echo shell\ script dns | whats
I'm just used to it, all other unix commands can do it, how would you implement it in a shell script?
After reading the following references:
I've edited the above script as follows:
Which will concatenate args + stdin in $@, so now it will work in the following scenarios:
It will parse correctly spaces with they came as args
But not when those parameters are passed through a pipe:
However that's a problem other unix utilities have too (-print0, -0, etc), so I can live with it.