Inspired by this answer: When I run type -p in the command prompt, it reliably tells me the path if the command exists:
pi@raspberrypi:~ $ type -p less
/usr/bin/less
pi@raspberrypi:~ $ type -p asdf
pi@raspberrypi:~ $
However, when used in a in a script it is as if the -p parameter is interpreted as a command of itself. It seems the type command ignores it as its option, because there is always some rogue text of -p not found in the result. It breaks the rest of the script:
#!/usr/bin/sh
main() {
for mycommand in $1; do
echo Checking $mycommand
loc="$(type -p "$mycommand")"
echo $loc
if ! [ -f "$loc" ]; then
echo I think I am missing $mycommand
fi
done
}
main "less asdf"
Output of the script:
Checking less
-p: not found less is /usr/bin/less
I think I am missing less
Checking asdf
-p: not found asdf: not found
I think I am missing asdf
Can you please help me out here? Is there something about the shell on a raspberry pi that is causing this?